Back to Basics of Programming
If you're new here, you may want to subscribe to my RSS feed. Thanks for visiting!

A subject close to my heart when it comes to programming is the lack of teaching in schools & college of the basics of programming. I fundamentally believe that understanding how the bare bones work assists in solving problems that we all face in our day to day programming jobs.
A good example is a general lack of understanding of how numbers are represented in binary. If I ask a group of 100 random programmers how many would know the difference between Sign & Magnitude and 2’s compliment? How many would know the answer? I bet you it is below 50%.
I hear a few of you saying “I don’t need to know that, I work with a programming language that does it all for me.” It is certainly a reaction I have come across before and anyone that thinks this would never ever work for me. Without understanding the basics it is very easy to make assumptions such as arbitrarily using of various data types without knowing how they are stored, what boundaries they may have to adhere to and even what the data types potential data range is.
So a quick test for you all. (Without using Wikipedia / Google)
1. What is 0xFFFF as a signed integer?
2. What is the difference between Little Endian and Big Endian?
3. Why is 2’s complement good for mathematics?
4. What is faster a binary shift or a multiple x2?
5. Can you type out 2,4,8,16 to… 32768 without having to think about it?
6. Do you understand the relationship between Nibbles/Hex & Octal?
7. What is Reverse Polish Notation?
If you can answer all the above then you will probably not learn much from my next few posts on ‘Back to Basics’ (although I would love your feedback.)
Comment by Niels on 2 August 2007:
I think I can do number 5.
For the rest..I’d have to read your post. So I probably will.
Comment by Rob Haynes on 2 August 2007:
1, 3, 4, 5, 6, and a general idea of 7. I had to look up 2 to remember.
The benefits in knowing these things is obvious with low-level languages or data storage. But even with high-level languages, there’s plenty of value to be found in how it affects the way you approach problems.
I can’t count the number of tables I’ve run into with text fields filled with “true” and “false”, or with ID fields large enough to handle trillions of customer accounts. How much processing time would be saved if those folks had a better grasp of the basics?
BTW, two’s complement.
Comment by TractorTyre on 3 August 2007:
I have learned all these in a different language, I’m not sure what Nibbles are, but the rest I know.
BTW, Big Endian
Comment by Nick Halstead on 3 August 2007:
Rob, glad you agree. Tractor, a Nibble is half a byte (i.e. 4 bits, which also equals one Hex letter)
Thanks for your spelling fixes guys this blog would be a lot more error prone without you all
In my defence bigbrother was sucking the life out of me last night while I was writing this 
Comment by Anonymous on 3 August 2007:
I don’t need to know that, I work with a programming language that does it all for me.
I do know the answer to some of the questions but I still think that I don’t need to know that to do what I do. To use the good ol’ car example, I do not need to know how to change a spark plug to drive a car. It might need to know some time in the future, but I don’t need to know until I need to know, in which case I’ll look it up in the car manual.
Don’t get me wrong, I do think that it would be useful for every programmer to know these things, but there is a difference between essential knowledge and knowledge that is “just” useful.
Comment by Anonymous on 3 August 2007:
Forgot to say that I’m a PHP programmer. And I meant “I might” not “It might”.
Comment by TractorTyre on 3 August 2007:
In my opinion there is nothing like a “PHP programmer”. There are programmers and there are people who are familiar to a certain extent with some of the tools that programmers use. Of course experience is one of the way to be an expert in something, so you may easily be a professional PHP user, but so long you call yourself “PHP programmer” you are not a programmer in the traditional sense. Programmers are independent of language.
PHP is one special language, created for one purpose: to ease dynamic web site building. It is a powerful tool, but the tasks related to PHP are limited in 95% percent to this field. You’ll never need to deal with threads, hardware, or other similar things which are common programming tasks.
PHP is like English, easy to learn, but difficult to master. In a high percentage of the PHP code I have ever seen, I met with solutions that made the hairs raise on my back. Especially sad are the queries. Database handling is a science on its own and this seems to overwhelm quite a few of the PHP guys.
Don’t take it personally, I’m just kind of sensitive on this topic, having needed to cope with a pretty bad “PHP programmer” lately, who happens to be a relative of mine, too. That made it especially damned hard
And to the car example, I don’t think you’ll find in the manual how to change a plug. That’s actually not a good example, because you need special tools to do it that not everyone has, usually (hobby-)mechanics. You’d need relatively long time to solve your spark plug problem (getting info and tools).
Changing wheels would be a more common example. If you don’t know how to do it, you probably also don’t know if there are neccessary tools in your car to do it, or if there is a spare wheel in your car. In case your tyre goes flat you have a problem. First you start reading manuals, then looking for tools, and looking for the spare wheel. After reading the manual and managing the change you’ll probably be uncertain in a couple of points, like how tight the screws should be. So you may need to drive for a while and stop again to check if everything is fine, eventually fix the loose screws. That’s about twice as much time as someone would need, who knows how to change wheels :).
Alternatively you can try asking someone for help. If you have luck, sooner or later you indeed find one who can help you enough. Or you get false information and following that you find out it was not good, so you start over again.
So it is useful to know your car
Comment by coditza on 3 August 2007:
The car example is a bad one, because, as a programmer you aren’t driving the car, but you are building it.
The example with the database field large enough to handle trillions of customer accounts isn’t a best example either, because that’s more or less related to common sense and experience. (more common sense in this case
)
Every programmer should know about types. I saw lots of questions like:
Why this doesn’t work?
[code]
$query = “SELECT * FROM bla WHERE title = Die Hard 4″;
$res = mysql_query(…)
[/code]
Comment by Fernando on 3 August 2007:
I totally agree with you with the lack of teaching the basics. I am studying to be a programmer, in an object oriented course, and I can identify with this problem. One of the most illogical things I´ve found during my course is they just teach you “this is a class”, “this is an object”, without a propper introduction to the whole paradigm.
Most of the students in the class have never even read a programming book, they don´t know other paradigms even exist. The way they teach you, you solve everything with objects. They don´t encourage you to read books either, after all, “you are a programmer, you don´t need to read”.
Later on the course they teach you on the fly: polimorfism, inheritance, etc.
They make fast courses these days so that you can go out and start working inmediatelly, there´s a big demand!
“Why would I care about the UI´s code, the IDE does it for me…”
But they are building just “programmers”, not “good programmers”.
I lost the test… expecting those ‘back to basics’ posts soon!
By the way, great blog, this is my first comment on it, but I´ve been reading it for a while. You are invited to check mine out.
Comment by pjw on 3 August 2007:
Those are pretty basic, though as a hobbyist programmer and a physicist I have not yet found knowing those 7 off the top of my head very useful. Though that may be because I have needed to do anything computationally expensive and do not need to work close to the hardware.
Comment by Matt on 3 August 2007:
How bare are the bones? You’re saying that programmers need to know about the nuts and bolts of bits and bytes. Fair enough, but do they also need to know about the electronics and transistors and stuff that implement the bits and bytes? And what about the laws of physics that govern the electronics? Maybe, maybe not.
We do programming at a variety of levels of abstraction. That level depends very much on the problem domain. I would argue that to be a good programmer you need to know about the level of abstraction you’re working in, and a little bit about the level of abstraction below that. If you’re writing a device driver, you care very much about bits and bytes. If you’re writing Minesweeper, you likely care very little.
As hardware becomes more powerful, programming languages are going to hide more and more of the low-level details, and your average programmer isn’t going to need to know about them. That’s not necessarily a bad thing.
Comment by CG on 3 August 2007:
@Matt - I think you hit the nail on the head:
We do programming at a variety of levels of abstraction. That level depends very much on the problem domain. I would argue that to be a good programmer you need to know about the level of abstraction you’re working in, and a little bit about the level of abstraction below that. If you’re writing a device driver, you care very much about bits and bytes. If you’re writing Minesweeper, you likely care very little.
In addition it might be useful to know a little about the layer above where you are doing development.
Yes I learned all that stuff - don’t remember it anymore - in fact I have forgotten way more than I know and I think that’s a good thing. Unless your a freak of nature you only easily recall that which you use on a daily basis. It doesn’t hurt to know that these concepts and mechanisms exist so you can revisit them if the need arises - but it’s not worth committing to memory.
Comment by Marc Palmer on 4 August 2007:
I completely agree with Nick’s attitude.
Part of the problem with our industry is that people recruiting for jobs where you really do need to use those skills often don’t even understand they are needed to do the job properly, so fail to recruit correctly (unlike Nick).
People who don’t understand the basics of programming will never be great programmers. They will likely write poor code that fails to take account of underlying language issues and performance, and these people accelerate us to the world where we -have- have 100GB RAM in our computers and 20 CPU cores.
I’m not saying we should all write the most ultimately efficient code, that does not make commercial sense.
However there is so much utterly awful code out there from people who just don’t have a clue. If they understood memory management and threading at a lower level, for example, they would produce better code.
Even understanding hex is extremely relevant, perhaps one of the core skills to have, if you are ever dealing with file formats, image manipulation or debugging mysterious crashes.
I’d love to know how many programmers even know what all this EAX: 0×00405858 stuff means that prints out when they crash their apps big time!
Anybody can build a house given a little learning. For me…. I’d prefer to know that I used someone who knew the right proportions to mix the cement with.
Comment by Prusch on 5 August 2007:
I have a little example, that might end up just muddying the waters, but anyway. This guy I’ve worked with, he’s a hell of a programmer, very fast, very smart, but inexperienced.
After he left the company, I had to deal with a number of codes he’s written, and quite a lot of times I found myself astounded with his code decisions, mostly due to a complete lack of care regarding optimization.
I know you should not optimize while coding, only after, during refactoring, and only if needed, but still, you have to think about it at some point, and this guy never did.
I think a part of this discussion is about knowing what happens under the hood, to be able to deliver good code, that performs well and produces the wanted results, and for that it seems clear to me that some low-level knowledge is a good thing to have.
Comment by Nick Halstead on 5 August 2007:
Marc, loved this quote .
Prusch, I do not think you have muddied the waters, the points you make I have come across all too often when discussing programming matters with friends at other companies. Any large scale project requires someone who understands what I have outlined. Without this understanding it is all too often the case that decisions are made without thought of the underlining structure which then have tiny knock on effects that finally result in massive bottlenecks.
It then takes someone months of refactoring to identify what has caused the bottleneck. A typical example storing 32 yes/no (boolean) values in a database? If you store them in (mysql/postgreSQL/oracle/etc..) as booleans/tinyint/ext.. how much space does it use up?
In C
struct {
bool val1;
bool val2;
(x32)
}
or
struct {
unsigned int val1 : 1;
unsigned int val2 : 1;
(x32)
}
Using visual studio, the top structure would give you 32×4 bytes = 128 bytes as a boolean is represented as 4 bytes, the second structure is telling the compiler to represent each value in a number of bits. So the second structure only takes up 4 bytes. If you made the same mistake in a database (by not understanding its underlying infrastructure) with 1 million rows,
Boolean as 4 byte
1,000,000 x 128 bytes = 122megabytes
Boolean as 1 bit
1,000,000 x 4 bytes = 3.8megabytes!!
It is not difficult to see that by just making one small assumption you have made a massive mistake and a potential huge future bottleneck.
Comment by Bill on 6 August 2007:
I don’t know the answer to any of those, but I’m extremely good looking. That’s all that matters, right?
Comment by antych on 6 August 2007:
I wouldn’t call it basics of all programming. These is fundamental knowledge for some languages but it may be completely irrelevant for others. If you build web applications it doesn’t matter for you how data is represented in memory.
And I’m really surprised by this - “lack of teaching in schools & college of the basics of programming”. It’s fairly common knowledge (as well as my experience) that universities make poor job at preparing you for real world programming problems. And that’s exactly because they teach you basics and theoretical stuff that has little use in real life.
I actually learned how to convert binary number at school. I also had to build a computer from parts and write assembler program to control it. I did a lot of things you could consider basic, but I consider them a total waste of time, because they could teach me really useful and important stuff through those years.
I might think different working on drivers or kernel now, but I build web applications for a living. So you cannot put all developers into one box and give them the same basic stuff, because nothing is basic in modern software engineering.
Trackback by Anonymous on 4 April 2008:
yung girls fuck…
yung girls fuck…