Semantic Error and Typographical Error.
When learning programming, no matter how smart you are, two types of errors are inevitable, they're semantic error and syntax error.
I am not new to programming, but it's been a very long time since I wrote something serious, so in other to avoid frustration while working on my prototype, I have decided to read a book on python it's titled Learning Python The Hard Way.
I am not reading this book as a newbie would read it because I know most of what is inside the book, all I needed was a revision of the terms and I would be good.
Oh boy, I was wrong!
Although, I can read a complex line of codes and understand what it does, I have issues getting my code to do what I want it to do.
What this means in simple term is that, even though when I write the code, the computer (interpreter) is able to interpret it, but the output it gives is not what I want.
You can liken this to pressing (5 + 2) on a calculator, while you expect the answer to be 7, but then you get 52 or 30. This is what semantic error is all about.
#This defines the function and receives argument variables.def cheese_and_crackers (cheese_count, boxes_of_crackers):total = cheese_count + boxes_of_crackers""" The next few lines print the argument variables"""print "\n You have %d cheeses! \n You have %d boxes of crackers! \n The total of your resources is %d:" % (cheese_count, boxes_of_crackers, cheese_count + boxes_of_crackers)print "\n Man that's enough for a party!"print "\n Get a blanket.\n"def number_of_rooms (Available_rooms, Assigned_rooms):Total = Available_rooms + Assigned_roomsprint "There are %d rooms in total" % Totalprint "Only %d rooms are available" % Available_roomsprint "%d rooms are occupied already" %Assigned_roomsprint "Do you still want to party?\n"print "We can just give the function numbers directly:"cheese_count = int(raw_input("How many cheese do you have? "))boxes_of_crackers = int(raw_input("How many boxes of crackers do you have? "))print cheese_and_crackers (cheese_count, boxes_of_crackers)print "Now that you're ready for party, answer these questions: "Available_rooms = int(raw_input("How many rooms are available? "))Assigned_rooms = int (raw_input("How many rooms are assigned? "))print number_of_rooms (Available_rooms, Assigned_rooms)print "Or, We can give the function numbers directly:"amount_of_cheese = 10amount_of_crackers = 50cheese_and_crackers(amount_of_cheese, amount_of_crackers)print "Let's do some math:"cheese_and_crackers(10 + 20, 5 +6)print "We can combine two the two; variables and math:"cheese_and_crackers(amount_of_cheese + 100, amount_of_crackers + 1000)
The code would execute, but the output would be wrong.
I have many issues with semantic error because I failed to read python documentation (I decided to learn on the job because this might take a week to wrap my head around it). Even though the semantic error is slowing my progress down, I still prefer this method, because I would in a week or two get over the semantic error as well as gain the right thinking hat for python.
The other error; syntax error is the normal typos you make when you write a piece of code, with this kind of error, you code would not execute, which means it won't work at all; because you're speaking a language the interpreter does not understand. This error might be frustrating, but it's not as dangerous as semantic error. Since the code won't work until it is fixed, you can be rest assured that you're still making progress until you get what is wrong and fix it. Sematic error would fool you into shouting "Eureka" until you realize that the output is wrong.
When I began programming (Almost five years ago) I learnt the basis, and one thing I believe over the years is that, a program should be able to do more with very short lines. I believe how short (minimal) your lines of code is would determine how smart a programmer you are.
The python book am reading contradicts that believe. Basically, a good programmer is the one that can write a code that a novice would understand to some extent. It's almost impossible for a novice to undersstand your code if you don't add english comment at the end of every line. So I am working on my commenting skills, because this project is a prototype, and I might not be the only one who will work on it in the nearest future, so I need to make it understandable to others to some extent.
Initially, when setting up my work environment, I wanted to use python 3.0+ but I later decided against it because 2.7+ is much more stable and I would prefer a stable and well known environment that trying to figure out my way in a newly developed technology (YouTube and Instagram were built with 2.7+).
Progress so far?
- Setting up python
- Speed reading a book on python
- Creating the functions
- Copying, Editing, and Writing files with a single argument script.
I guess thats all for now, I would update this blog as I progress.