A note on code conventions used on this blog.

Posted by Chris on October 24, 2017

A note on code conventions used on this blog.

So far, 99% of the coding examples on this blog are in Python. As far as Python goes, I use the following conventions:

  • all variables in camel case (By the way, you can see a neat comparison of camel case and underscore here. - 26K worth of votes as of 24th October 2017, when this post was written.)
  • all variables begin with a single letter that describes their type, ex. for the python types:
iMyInt = 1 # IntType
fMyFloat = 1.0 # FloatType
sMyString = "string" # StringType
lMyList = [] # ListType
tMyTuple = () # TupleType
'''
etc...
'''

I will even go as far sometimes as to declare a new variable when the type changes, for example, converting a string to a list of strings:

'''
We could just as easily use 'sString' on the left hand of the assignment as python would handle the type conversion, but doing this frequently all over the code can lead to confusion in types
'''
lString = sString.split()

Of course such notation isn’t necessary and at times could even be a hindrance to understanding the code, but I think for anyone learning and for the sake of a clean way of following what exactly is happening in the code, it is helpful.

I hope this quick note was helpful.

As always, enjoy the posts everyone! :)

-Chris

Leave a Comment

Thoughts? Critiques? Just saved a bunch of money by switching to GEICO? Leave a Comment!