How to develop good software

As a software developer, I’ve come across many horrors in coding over the years. It’s no secret that most developers code things fast and ugly to get stuff out the door. But something strange happened to me recently; I think I am finally becoming a better coder.

I’ve been developing an ERP/MRP/CRM by myself for the past 3+ years and I’m finally reaching the release date. I’ve been testing the product with two clients for the past year, and naturally, many bugs have popped up out of nowhere, many features have been requested, and so on. You know… the typical software development cycle plagued with inadequacies.

However, I’ve finally learned a valuable piece of information I’d like to share:

Features, not rules.

I went in with a bunch of rules for the last meeting I had with my clients. They had to follow these rules to use the new features in my system correctly. They needed to follow certain processes in an orderly manner, they needed to avoid placing certain characters at the start of some files, they needed to use the correct extensions, they needed to avoid using certain half-baked process, they needed to process files at the end of the month and not in-between, etc.

Naturally, they were a bit taken aback. They are not computer-savvy, and they have a hard time grasping new things. “Why?” kept comming up all the time. I tried to explain that this is natural in a system so big, there are certain rules you must learn to avoid entering bad data, or messing up parts of the system, etc.

Halfway through the training I realised I was doing things the wrong way. Whenever you have to write down more than 3 rules for a process, it is almost always better to make the system handle all possible exceptions instead, and inform the user appropriately when they have made a mistake. It is easy to do this with forms for example, you write down some regex rules (or use JQuery Validate), you add extra back-end validation, you use a “form/validation” class, etc. However, when the processing takes place in the back-end (e.g. a file parser that changes content in the database), it is easy to expect too much of the users.

I left the meeting with all the rules I had written down scratched out and a page full of tasks to be performed.

I think it is vital for us to embrace this. A system must be able to handle anything thrown at it, it must be able to validate incorrect data, file extensions, and any other exception you may think of. It seems natural, most of you are thinking “this is so obvious, why write a blog post about it?”. Why? Well, because I keep seeing these kinds of mistakes all over the place. I’m sure many developers out there still think “oh, I’ll just explain the user how to do it”. Then you get a ton of calls of users asking why this or that is not working, and you have to explain that there is a certain process to be followed.

The answer is simple: Think before you code, and make whatever you code “think”.

On political parties and why they should not exist

I was quite amused by a G+ post written by Google co-founder Sergey Brin today, which in summary, says the following:

I must confess, I am dreading today’s elections. Not because of who might win or lose. But because no matter what the outcome, our government will still be a giant bonfire of partisanship.

In fact, I have thought the same for some time now. Just before the Mexican elections, I had a long debate with an ex-friend of mine about this. We talked about how there should be no political parties, but instead, individuals backed by people with similar thoughts, where they aim to change the country following X or Y strategy, without naming themselves as “conservatives” or “liberals”, but rather as politicians with X or Y views. He strongly disagreed, to the point of ending our friendship because instead of analysing and debating this rationally, he was stubborn and single-minded.

In my view, you shouldn’t divide the political system into two bands. There is always scope for one person to believe in some things from one side, and some things from the other. I believe it shouldn’t be about “the way the party does things”, but instead, more about “what will benefit the country the most”.

This article, published today on TechCrunch, briefly talks about this:

“No free country has ever been without parties, which are a natural offspring of freedom,” wrote James Madison.

Of course, I believe this is absolute rubbish. Political parties are not natural offspring of freedom. Freedom is one thing, political parties are another. Whilst siding yourself with a political party can be considered freedom of choice, the choices made by political parties are often single-minded unilateral decisions which lack freedom of thought, as they are constrained within boundaries imposed by the political parties’ belief system.

The article furthermore offers the following possible solution:

One popular, if contentious, solution to bitter partisanship is a multi-party system, where multiple groups are constantly forging new alliances based on specific issues, rather than a constant zero-sum tug-of-war where each party has the same enemy on every problem.

However, I digress. A multi-party system will lead towards more confusion.

So what do we need?

What we need are intelligent, knowledgeable, enthusiastic people, who put their country before their set of beliefs, to put together a group of people with similar beliefs that will back this person, economically, emotionally and whole-heartedly, so that this person may get into office. This person would not be part of a political party, but instead, would propose a plan, establishing feasible time-lines, whilst adhering to a set of rules that would govern his/her time in office (apart from the constitution, of course).

This would also make voting much simpler of course. Don’t think left-right politics. Think alignment to values and proposals. Voting could be separated into three stages. The first stage would consist of a questionnaire, where you answer yes/no to a set of questions concerning the country, society, economy, education, business, war, and a few other factors. This questionnaire would give you a list of three candidates (and their backing groups) that fit the answers the best. The second stage would consist of an analysis of the available options, studying the background, the plan, and the ideas of each candidate. The third stage would be the actual voting process as we know it: Select a candidate, vote.

Of course, this can’t work without guarantees. Each candidate would have to guarantee that the plan will be followed, and if catastrophic misalignment of the plan ensues, that person would leave office and a new voting poll would take place.

Of course these are just a few ideas I’ve been thinking about for a while now. Implementing these may be next-to-impossible, considering the system we currently have, and the rate it takes to ‘commit new changes’. Nonetheless, I believe it would bring forth a better system.

What say thee?

Avoid dropping out at all costs

After reading this post, I got the urge to write a reply of some sorts, with my thoughts about dropping out to build a startup.

My advice: Don’t do it, there is always time, but it’s harder to get back to studying once you’ve dropped out.

What set me going was this last paragraph of the post

As a result, my advice to anyone thinking of dropping out is to keep studying, and use every opportunity to build projects and startups on the side. When something starts to work, you’ll have that same feeling that many others have, and you’ll know that it’s your duty to keep building it and bring it to the world. Until that happens, keep studying and keep building. When it happens, drop out slowly.

There is no such thing as “drop out slowly”. You either drop out or you don’t. Once you’ve got your own startup, you are “supposed” to put all your energy and time into it. People take Steve Jobs, Bill Gates, and Zuckerberg as examples, and generally don’t go back to studying, because “there is no time for it”.

As the article says, you go through a very fast, compressed, learning stage when you have your own startup. You learn so many things that it kind of feels irrelevant to go back to studying.

My story

I’m not a dropout, but I’ve still found my way to building startups, making money, and following my dreams.

I’ve worked since I was 17, whilst still in high school. I started off working as a developer and photographer at a jewellery factory. I started university, and joined a software development firm. I chose a university that would adapt to my work hours. Sometimes I would go to uni at night, other times I would take online courses, etc. My bosses knew that schools comes first, so when I had to take a mid-day course for a few months, they would allow me to leave the office for 2 hours at lunch time.

At the same time, I was working on starting my own business, developing CMS and CRM systems. So, how can you handle two jobs and uni at the same time? Trust me, it’s possible. It’s all about time management and good communication. As long as you know how to prioritise, organise, communicate, schedule, and perform well, then you can master anything in life.

So, fast-forward a few years, and I’m in Scotland doing a master degree in Artificial Intelligence, whilst working part-time for a financial software company, and freelancing as a web designer in my spare time.

I managed to get through the course, fly back home, and carry on with my start-up. Right now I’ve got over twenty clients, whom I do web systems, websites, and other custom projects for.

You don’t need to drop out to get your own projects going. You just need to know how to organise your life, find a flexible course or university, communicate well with your clients, co-founders and university staff to let them know what you are doing, organise your time adequately to cater for all your needs, and get to work.

The number one thing I learned

I took away from this experience that what you learn at uni, you apply in your start-up and other jobs, and vice-versa. It is a constructive symbiosis that will help you grow intellectually, as well as economically. Furthermore, when you finally graduate, you will be much better prepared to manage your start-up than you would have been if you would have dropped out.

Now, my experience and words might not work for everyone, but it certainly worked for me. So think first, analyse, compare experiences, do research, and then decide. Because when you drop out, it might be the last time you ever go back to the classroom.

How to deploy a static page to Heroku, the easy way!

I wanted to upload a simple website based on HTML, CSS and JS files, with a few images, and a favicon. So I registered at Heroku, bought a domain name, followed the Heroku instructions on how to set up the “Toolbelt” and GIT.

So I thought I was all set up: I created a folder with an index.html page, with the text “Coming Soon…”. I set up the repository, and tried to commit to Heroku, only to receive a message similar to “This is not a code repository” or something similar. Heroku is primarily aimed at apps running on frameworks, like Ruby on Rails, Django (Python), node.js, or… ahem… PHP.

So it seemed incredibly dumb that it can handle all these frameworks, but it doesn’t let me upload a static site! So I searched about, and found out how to do this by setting a demo (barebones) ruby app, as well as a Sinatra variation. However, this didn’t convince me. First of all I didn’t want to place my code in a “public” folder. No. I was probably being a bit picky, but when I expect things to work a certain way, I get annoyed when barriers are put up in my way.

I finally figured out that Heroku allows you to publish PHP sites as well, with NO configuration needed! That’s right, just create your .php files, and it will figure out that the Heroku app should run PHP for this site, and it will auto-configure the app to run on the latest version of PHP/Apache.

So here is how you do it:

Rename your index.html to home.html or something similar.

Create an index.php file with the following code:

<?php include_once("home.html"); ?>

That’s it!

Now go to your app folder in CMD (or Bash), and commit your code to Heroku using the following:

git add .
git commit -m 'Change this to a meaningful description'
git push heroku master

 And finally, you should get the following:

-----> Heroku receiving push
-----> PHP app detected
-----> Bundling Apache version 2.2.22
-----> Bundling PHP version 5.3.10
-----> Discovering process types
Default types for PHP -> web -----> Compiled slug size: 9.5MB
-----> Launching... done, v4

Congratulations! You have published a static site to Heroku with one line of PHP code :)

From a screenshot to a CSS ‘image’

I must say I was pretty impressed when I saw the Mona Lisa rendered using pure CSS. While talking about it with a friend, I told him I thought it had been done using an automated process, where a program would read an image as an array of pixels, and would output an HTML file containing a CSS section with a bunch of box-shadows that “represent” the image.

Why “represent”? Well, the amount of CSS required to represent each pixel in the image would be massive. Therefore, the better approach is to take a pixel from each 5×5 pixel block, which will represent that block, and use a CSS box shadow which will converge (fade) into nearby pixels. Therefore, giving an approximate representation of that the full image looked like.

So I set about doing a Python program that would do this. Shortly after finishing the Python version, my friend pointed me towards this file which does a similar thing using PHP. Oh well, at least I had fun coding it.

So, my program basically allows you to take a screenshot of your desktop and convert it into a CSS version of the image, or you can take a png/jpg file and do the same thing.

The output (example below) is pretty fuzzy, but I’m thinking I can probably improve it a bit by tuning the spaces/pixels, or by getting a better “sample” of the overall colour that predominates in a 5×5 pixel section of the image, instead of just using the first pixel in the section.

Get the code from Github, and if you have any suggestions, feel free to leave a comment below (or on Github).

Screenshot