Tuesday, April 18, 2017

Now You Have Two Problems

Now You Have Two Problems

There’s a programming joke that goes like this
You have a problem and you think “I’ll use a
regular expression.” Now you have 2 problems.
Some people misuse regular expressions, but sometimes they are just what you need.
This Stack Overflow question involves parsing a string containing math operators and
integers. The answers ranged from simple to complex, and at least one answer required reading The Dragon Book.
In the spirit of “doing the simplest thing that can possibly work”, I present this regular expression
[()*/+-]|\d+
  • [()*/+-] means match one character from the set ()*/+-
  • the \d stands for a single digit and the + means appearing one or more times
  • the | is the logical OR
So the expression means "match one of these punctuation characters OR an integer number". It will silently ignore anything else such as whitespace, and this is exactly the behavior we want.

Sunday, April 16, 2017

Top 3 Reasons You Need a GitHub Account

Top 3 Reasons You Need a GitHub Account

Reason #1 : GitHub is your new resume

Having a public GitHub repository lets potential employers see samples of your work.

Reason #2 : GitHub lets you work in teams

GitHub supports team projects in 3 ways
  1. it provides a common workspace for the team
  2. it saves a complete copy of all your files
  3. it lets you see what changes were made and who made them

Reason #3 : GitHub has great resources for students

The Student Developer Pack gives you free access to over 20 professional software development tools.
So don't wait. Go create your GitHub account today.

Tuesday, April 4, 2017

Reading Python error messages

What every beginner needs to know

It's normal to make mistakes when you first start learning to program. Python uses exceptions to report errors. Usually, your program will just print an error message and abort. These error messages contain a lot of information, but you have to know how to read them.


Here’s a sample error message




The message has 2 parts
  1. A traceback, showing the path taken by the program when the error occurred.
  2. The name of the exception followed by a short description.


The traceback is important because it shows the exact line of code containing the error. In this case, we can see the problem is in line 9 of the “C” method. We can also see how we got there
  • method A (line 5), which called
  • method B (line 7), which called
  • method C (line 9), where the error occurred

The last line of the message reads “ZeroDivisionError: float division by zero”. This lets us know that dividing by zero is not allowed and we need to fix it.

So don’t panic the next time one of your programs fails. Read the error message carefully and you can probably figure out what’s wrong.