Hacking vs Coding

Today, I realised that working styles can be rather different.

My working style

  1. Find template or code that already works.
  2. Modify and remove whatever you do not want
  3. Find code for additional functions
  4. Throw it in and find some way to make it all work together, if cant work, spend 15 mins trying to fix it, if still cant, just throw it out and find another piece of code.
  5. Rinse and repeat

To me, if the code works and fits in why bother figuring out the the intricacies and details of the individual lines and components. Anyway, it was only through conversation with my partner did I realise how little I actually know about what I had 'written'. All i knew was "modify this 4 lines and add this line here to create a page", "remove this section of code if you want to remove this div" so on and so forth.

My partner on the other hand started off completing structured lessons and analysed and dissected every line of code starting from the very top (just like a compiler would), importing of libraries, wanting to know where the libraries were, what functions and so on. Honestly, I couldn't be bothered learning to code Hello World in 20 different languages and if i needed to import the library for code to work, ill just throw in the imports.

However, the hacked code was starting to get messy and while everything looks nice on the front end, it was getting difficult to explain what is going on in the back.Every new functionality added would be like trying to run loops around existing code. Tidying up the code was gonna be difficult since I understand probably only 10% of what is going on. I had to really learn the language to fix up the mess.

Despite all that, I realised something else too. Hacking code required a unique skill, the ability to "guess" which particular code needed to be changed for something to work. If it was dynamic, it was likely to be in php, static likely to be in HTML and so on, and somehow based on function name and values, through a process of trial and error start removing/modifying/adding code. Hacking also required big picture knowledge, you needed to know how to implement your functionality. E.g. php query db for results and outputs to HTML. You would get nowhere trying to use HTML to do a SQL query.

Anyway, for big projects with extensions and maintenance, it would probably be a good idea to write good code. Hacking would be good for small stuff, one time off kinda thing. E.g. I hacked out the commenting system for this CMS in 2 minutes even though I cant write php code for nuts. Simply copied over the entire comment chunk from another template and shoved it under the article section and copied over all the CSS required for the comment boxes and it just worked. Miraculously.