code

Everyone’s A Coder

Question:

Are we headed to an era where everyone should know how to write at least some rudimentary code?

 

Learn to Code

Today, there are many sites on the internet offering to “teach you to code.” Two of which are KhanAcademy and CodeAcademy.  These sites offer a selection of topics that can be worked through in the span of a few hours.  Can it be done?  Sure.  Matter of fact, I think they are good resources to get you started.

Differentiating Computer Science

Computer science is more than just coding.  Wikipedia defines computer science as the following:

Computer science is the scientific and practical approach to computation and its applications. It is the systematic study of the feasibility, structure, expression, and mechanization of the methodical procedures (or algorithms) that underlie the acquisition, representation, processing, storage, communication of, and access to information, whether such information is encoded as bits in a computer memory or transcribed in genes and protein structures in a biological cell. A computer scientist specializes in the theory of computation and the design of computational systems.

Simply put, Computer Science is more than programming, though most computer scientists do write code.  On the topic of code, colleges don’t so much focus on languages as they do the theory, math, and algorithms.  This allows graduates to quickly assimilate new languages and ideas.

Does a product (or code) have to be perfect?

The answer is a pretty resounding “No,” but bad or inefficient design might harm long term viability.  In terms of a startup, I’d say a Software Engineer should become involved soon after completion of the MVP if not before.

Can everyone be a coder?

Yes!  I believe that in the future everyone should know how to write at least some code.  Right now, JavaScript and Python are the best candidates that could be learned by all.  With it leaning in JavaScript’s favor with Node.js.  Though, if you have serious aspirations to getting a career writing code, I suggest a formal degree.

 

Posted by Chad Dotson in Software Engineering, 0 comments

Project Excelsior – Technology Update

current_stack

Current Project Excelsior Technology

For the past month or so I’ve been working on a little side project that I’ve dubbed “Project Excelsior.”  I’ve not had an abundance of time to spend on it over the past few week, so I’m just now wringing out some of the technology stack.  I’ve almost decided completely on the MEAN stack.  I’m close enough to a final decision that I’ve started prototyping the server side.  I’ve not worked with angular before, but I am familiar with ember and backbone.

 

Posted by Chad Dotson in Diversions, Programming, Software Engineering, Technology, 0 comments

No Comments – A Failure Twice

Everyone that writes code has encountered or written their fair share of undocumented code.

A failure twice?

I was encouraged to write this article because of something I read about the pinball game that once was included with windows.  According to the article on MSDN, the pinball game was removed due to a bug that should have been fixable.  However, the overall qualify of the code made repair impossible and the game was removed from the distribution.  Two major items can be taken from this:

  • Failure 1: The could should have been self-documenting / few comments required.
  • Failure 2: Code not easily understood should have been commented.

Properly commented code can be tricky!

In college they push you to comment your code while not stressing that over documentation is also bad.  I remember writing programs that had comments on almost every line for assignments.  In the end it doesn’t buy you anything, it just restates the obvious and clutters the solution.  In the workplace, comments and whether or not the code needs them are hit and miss.

Some notes about comments:

  • Many comments are an acknowledgement of your failure to communicate.  Write better self-documenting code.
  • Outdated or wrong comments are worse than no comments.
  • Consider refactoring code that’s not self-documenting.  I find one of the biggest places this can be done is extracting methods from if statements.
  • Choose a good, descriptive names.  I’m a little wordy in my names, but in the end most of my code can almost read like a sentence.

Remember

The code is your best documentation.  Think about what you want to communicate with it and how to be as clear as possible.

Posted by Chad Dotson in Doing Things Better, Programming, Software Engineering, Tips, 0 comments

Node.js vs Python vs PyPy – A Simple Performance Comparison

NQueensGraph

IMPORTANT NOTE: The NodeJS algorithm had a slight discrepancy in it.  See this article for a correction to the performance comparison section of this article.

The Algorithm

Yesterday, I decided to try translate my algorithm for calculating N-Queens to JavaScript.  I’ve implemented the same single-thread, brute force, recursive algorithm in many different languages with the biggest difference being the syntax of the language.  Once I completed the JavaScript Implementation, I ran the program with the latest version of Node.js.

The Findings

I knew Node was fast but it still surprised me.  As you can see by the included charts, the performance difference between Node.js and out-of-the-box Python is pretty significant.  Its not until the algorithms complexity and recursion depth hit certain limits that Node.js’s performance starts to falter.

Node.js and CPython – What’s The Difference?

You might ask what is behind this performance difference.  The answer is actually pretty simple.  It all boils down to how the code is being executed.  Node.js uses the V8 JavaScript Engine (Wikipedia | Google) written by Google and a part of the Chrome Browser.  V8 includes a just-in-time compiler that compiles the JavaScript to machine code before execution and then continuously optimizes the compiled code.  Python is a bytecode interpreter; meaning that the default interpreter (CPython) doesn’t execute Python scripts directly.  Instead, it first generates a intermediate file that will later be interpreted at runtime.

Ways To Get Better Performance

If you want to use Python, we can overcome the differences between Node.js and vanilla Python by using PyPy, an alternative implementation of Python that includes a just-in-time compiler.  For the algorithm I wrote, you can see a pretty good performance boost over Node.js when using PyPy.

Special Notes

  • I’ve placed my source on GitHub at the following url: https://github.com/chaddotson/puzzles
  • This is just with one type of algorithm, the best solution might and probably does change depending on what type of application you are researching.  For webserver performance, Node.js is slightly better than PyPy running Tornado.
  • This algorithm is a simple brute force algorithm, there are many faster and better ones out there.
  • At a board size of 15, Node.js could no longer run the algorithm due to its maximum recursion limit.
memory_usage
memory_usage_chart

Edit – A Follow-Up

The original focus of this article was shear performance, but I’ve received a question regarding the memory footprint of the 3 methods.  I think that is a very good and valid question.  So, I reran the tests to capture the peak memory utilization by each.  For this test I used “/usr/bin/time -l” to capture the maximum resident set size.  While this isn’t exactly the peak amount of memory utilized by the algorithm, it is sufficiently close to report on.

New Findings

Upon rerunning the tests for capturing memory utilization, I found that for the most part memory utilization contrasts performance.  A higher memory utilization isn’t really unexpected, if you think about it.  Essentially, the jit is sacrificing memory for performance.  In most cases, this isn’t really that bad.  Using a jit is just a cheap way of boosting performance of code written in an interpreted language.  The boost in performance, speed of which it was written and the maintainability of it outweigh memory utilization concerns in many cases.

The Oddity

As you can see, I’ve included a chart covering all the solutions for boards 8×8 to 14×14.  During most increments in board size, the memory utilization seems to increase exponentially; however, when we hit the 14×14 board size we see all the cases level off at relatively the same memory utilization of around 300 MB.  At this time, I really don’t have a good answer for this.  I could certainly speculate, but I’d rather not until I know more.

 

Posted by Chad Dotson in Programming, Software Engineering, Technology, 28 comments

DateTakenPhotoSorter.py – A python script for sorting photos

I decided this script was a necessity since I’ve been arranging my photos based on date taken since I bought my first Canon point and shoot.  After buying my Nikon 5000, I was disappointed to find the Nikon’s sync software did not break photos out into directories based on the date they were taken.  Yesterday, I finally had time to sit down and code it up.  This script should work on any platform and can work via either command line or via drag-and-drop.  Simply give it one or more directories using either of those methods and it will sort the photos in each directory based on the “Image DateTaken” Exif field.

Download Link: DateTakenPhotoSorter

SVN: http://cdotson-utilities.googlecode.com/svn/trunk/DateTakenPhotoSorter

Posted by Chad Dotson in Photography, Programming, 0 comments