A sad state of affairs

By NMe on Friday 27 March 2009 12:38 - Comments (10)
Category: -, Views: 8.287

No other business suffers so much from incompetence as the IT business. There, I said it. When you're an incompetent cleaner, salesman, technical designer or architect you'll be found out soon enough, but as a programmer your bad practices can and will make it into production no matter how good or bad you are. A programmer's true incompetence often isn't discovered before it's too late.

Programmers are often seen as some kind of computer god. They can do everything with computers, which is why so many incompetent managers give programmers a side job of maintaining the company network as well. Although most of us are capable enough of setting up a home network, a company network is a totally different ball park. Yet, for some reason the end users of the network don't complain too much about it, because if the IT specialist says he can't make it any better, it must be impossible.

Because of this extra credit that programmers naturally get from the layman they can pretty much do whatever they want when they're in a small or understaffed team. They can pretty much teach themselves anything, not have it tested or approved by someone with more experience and just make use of it for the rest of their career. I've seen a lot coming by in my experience as a moderator of the Programming forum on GoT. Many of the most common bad practices are not only displayed by students or hobby programmers, but by corporate programmers as well. I've seen code teeming with bugs and security leaks, and when pointing them out the topic starter either shrugs and moves on without changing a thing or mentions how he never heard about for instance SQL injection and will make sure it doesn't happen again.

Of course being aware of weak points in security and general bugginess is one thing, but what I think is more important is the fact that some of these people never had the real mindset of a programmer. If you're supposed to be a programmer, you will think in a certain way. For instance you'll see repeating structures and recognize that if you're repeating yourself, there's bound to be a way to do it that doesn't involve as many lines. I'll show you by means of an example I came across on the forum this week. I will withold the name of the creator of this bit of code.

PHP:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
$a1 = str_replace('                  ','-',$line);
$a2 = str_replace('                 ','-',$a1);
$a3 = str_replace('                ','-',$a2);
$a4 = str_replace('               ','-',$a3);
$a5 = str_replace('              ','-',$a4);
$a6 = str_replace('             ','-',$a5);
$a7 = str_replace('            ','-',$a6);
$a8 = str_replace('           ','-',$a7);
$a9 = str_replace('          ','-',$a8);
$a10 = str_replace('         ','-',$a9);
$a11 = str_replace('        ','-',$a10);
$a12 = str_replace('       ','-',$a11);
$a13 = str_replace('      ','-',$a12);
$a14 = str_replace('     ','-',$a13);
$a15 = str_replace('    ','-',$a14);
$a16 = str_replace('   ','-',$a15);
$a17 = str_replace('  ','-',$a16);
$a18 = str_replace(' ','-',$a17);
$a19 = str_replace('--','-',$a18);
    
$linearray = explode('-',$a19);


What this is supposed to do is split up lines with a lot of whitespace into the different words. If you're a programmer, you'll see that the easiest way of reducing these lines to something more generic is the following.

PHP:
1
2
3
4
5
6
7
$spaces = '                 ';
while (strlen($spaces) > 0)
{
    $line = str_replace($spaces, '-', $line);
    $spaces = substr($spaces, 0, -1);
}
$linearray = explode('-', $line);


This will do exactly the same, yet in another way that doesn't fill your screen with a wall of text and that doesn't fill your memory with twenty different variations on the same string. It may not be noticably faster, but it's a better way of doing it. Also, it's just the way a programmer without a thorough knowledge of the language will handle it, because in the end it can all be done in one function call.

PHP:
1
$linearray = preg_split('/\s+/', $line);


My first correction would be something any programmer should be able to think of. If not, they'll have a hard time performing well in any business because they lack the mindset to be able to tackle logical problems. The second correction I made would be something you'd be able to think of when you've got a thorough knowledge of the language and the framework that comes with it. The lesser gifted programmer will not be able to conjure any of the two given samples and come up with something like the first bit of code instead. And while it does the job, it doesn't do so particularly well.

This last bit is exactly what the problem is for many businesses. A produced piece of software may seem to work, yet under the hood it could contain code like we can see on TheDailyWTF every day. How this ends up costing the same companies a lot of money can of course be read on the same site as well.

So who is to blame? Well, I'd say schools are. Teachers are seldomly in touch with what really is going on inside businesses that will actually employ their students. Subjects at school are more often than not 5 years behind on developments inside businesses so by the time a student graduates his or her knowledge will be up to 9 years behind. This means a lot of catching up, and many recently graduated people are not ready for that challenge. Also, schools tend to put more focus into teaching their students how to program in yet another language than into teaching them some good practices in security, usability and for that matter: actually teaching them how to program instead of how to write in a certain programming language. The two are not the same.

A sad state of affairs indeed.

Volgende: The snag of leadership 08-'09 The snag of leadership
Volgende: Justice at last 03-'09 Justice at last

Comments


By Tweakers user Phyxion, Friday 27 March 2009 13:03

"So who is to blame? Well, I'd say schools are. "
I don't agree completely with this statement, even though some schools might do a better job, it's also a lack of time and a lack of thinking. Most programmers go on the easy way with just copy and pasting their code and probably never heard that copy+paste is bad in programming. Even with the slightest knowledge of programming and Googling you can easy find a billion examples about cleaning up your code and also improve speed. However, most schools never teach how to optimize code, but since this isn't so complicated everyone can learn it themselves.
However, as this is PHP and following the talk about PHP in [alg] Slechtste programmeervoorbeelden deel 4 I have to agree that most PHP files are pure crap.

By Tweakers user NMe, Friday 27 March 2009 13:11

It's not because it's PHP that this stuff is crap. It's crap because the person who wrote it did not grasp the essence of looping control structures. I could have written the same lines of code in just about 200 different programming languages, portraying the same point I am doing now.

Schools should help people find out if they're actually cut out to do something or not. Someone that does not have the talent to be a programmer can still do it, but it will take them much more effort. Just like a dyslectic person could be a great writer although it will take them a lot more effort. This is an important similarity that people often fail to say. You can learn anything, but if you lack a certain built in skill it will take you a lot more time and effort to learn. Schools should help these people with their own courses focusing on the mindset instead of on learning yet another language.

By Tweakers user Lukse, Friday 27 March 2009 14:20

Schools should help people find out if they're actually cut out to do something or not. Someone that does not have the talent to be a programmer can still do it, but it will take them much more effort. Just like a dyslectic person could be a great writer although it will take them a lot more effort. This is an important similarity that people often fail to say. You can learn anything, but if you lack a certain built in skill it will take you a lot more time and effort to learn.
You couldn't have said it any better!
In my opinion, programming should start as a hobby. It's not something you can learn by going to school for three years.
The basic skill programmers should have is "logical thinking". Without that, please don't even try it!
And that's what's wrong with schools. They let everyone follow any course they want. Teachers at my school even simplified the final exams, because otherwise too many people would not make it! I mean, come on?!

By Tweakers user H!GHGuY, Friday 27 March 2009 19:21

The first problem is that school is full of gamers who think computers is their life so they should start programming.
The second is that school is becoming easier and easier and that those who don't belong there don't fail. Think of http://www.joelonsoftware...ePerilsofJavaSchools.html
The third is that even nerds think of the job as 9-5 programming, while in fact in most companies it's a mix of many things. In company A you'll be responsible for the whole project from analysis up to testing, company B might be very customer oriented, while company C might provide a healthy mix of various projects.

There's probably more problems, but these are some of the more important ones that I can come up with.
Fortunately, I'm priviliged to be part of team of mostly skilled colleagues so for now, you won't hear me complain.

By Tweakers user NMe, Friday 27 March 2009 20:50

Don't get me wrong. I'm pretty happy with my "job" (internship) right now, as my colleagues are actually all competent people. I do however also go to school (just finishing) and I see a lot of crap in /14 on the forums. I see around me every day what's going wrong in the world of programming and I'm not liking it one bit. I'm just at the beginning of my career and if I can avoid it then I will, but I'm sure I'm going to have to maintain someone's horrible mess of a code some day because the untalented person that made it didn't get the guidance he needed. The thought alone almost makes me cry out in despair. :P

[Comment edited on Friday 27 March 2009 20:51]


By Tweakers user RobIII, Friday 27 March 2009 22:15

I'm no PHP programmer but isn't this even easier (apart from the regex ofcourse):


PHP:
1
2
3
while (strpos($line, '  ')>0) {
  $line = str_replace('  ', ' ', $line);
}


Pure genius :Y)

Anyhow; nice blog and I have to agree with you. I wouldn't blame just the schools; other factors are often for example bad guidance during internship or dumping interns with the non-talented guys so the 'bad practices' spread like a virus. The newest programmer-to-be will pick up the wrong practices and start spreading them theirselves.

And then there's the matter of assigning totally unreal, plain boring or even stupid and impossible tasks to students that aren't up to the task forcing them to 'lend' some code somewhere; copy/past it; hack away at it and turn in a shitload of code that 'sorta works' and then getting graded enough to pass exams :X I've seen it countless times.

The main point is, however, as stated in your post the (usual) complete and utter incompetence of schools. History teachers teach programming because they couldn't find anybody up to it and he/she sorta wrote an Excel macro once. Or the guy owning a software company in front of a classroom letting students do jobs he can sell to his/her customer. And most of the time the teachers have been stuck in the boring classrooms long enough to loose all feeling and got out of touch of what has been going on "outside".

Nah; I don't think much of schools (in IT that is). Don't get me wrong: go pass your exams and graduate. But then make sure as hell you land an internship or job that actually teaches you everything you missed out in school. And that takes guts: you need to be confronted many times with what you thought and were tought was right is now wrong. And it takes real passion for the profession to want to know more; get into it deeper and better. Really grasp all the concepts. Sadly, most graduates focus on landing any job; as long as it pays nice and the company car is cool.

By Tweakers user MikeN, Friday 27 March 2009 23:41

I hope you understand \s is not the same as a space?

Also:
that doesn't fill your memory with twenty different variations on the same string
In some languages (don't know about PHP) strings are immutable, so your method will generate the same amount of strings ;)

By Tweakers user NMe, Saturday 28 March 2009 01:03

I'm no PHP programmer but isn't this even easier (apart from the regex ofcourse):

PHP:
1
2
3
while (strpos($line, '  ')>0) {
  $line = str_replace('  ', ' ', $line);
}


Pure genius :Y)
Yes, that would be even easier. The point for using the variation I did was mostly that it does exactly the same as the lengthy bit of code by simply using a loop. I was reducing the number of lines using the same solution to make my point clear. :P
In some languages (don't know about PHP) strings are immutable, so your method will generate the same amount of strings ;)
As you may have noticed I reuse the same variable. It will perhaps put the string in another bit of memory space, but since there are no references to the old string anymore, the old string's memory can be reused. :)

By Tweakers user RobIII, Saturday 28 March 2009 14:25

Yes, that would be even easier. The point for using the variation I did was mostly that it does exactly the same as the lengthy bit of code by simply using a loop. I was reducing the number of lines using the same solution to make my point clear. :P
And your point was clear; I think you missed mine :+
My point was that, a a programmer, you must sometimes be able to 'think outside the box' and not write code as you'd solve a solution by hand. My example (and 101 variations would be possible, I'm sure) demonstrates a whole other approach to get the result required. Programmers should be able to come up with things like this even though it isn't directly a 1:1 translation of their solution taking care of a problem.

By Tweakers user NMe, Sunday 29 March 2009 01:46

And your point was clear; I think you missed mine :+
Stop confusing me then! :D
My point was that, a a programmer, you must sometimes be able to 'think outside the box' and not write code as you'd solve a solution by hand. My example (and 101 variations would be possible, I'm sure) demonstrates a whole other approach to get the result required. Programmers should be able to come up with things like this even though it isn't directly a 1:1 translation of their solution taking care of a problem.
Very much so, however these are two different ways of thinking. One involves solving the problem logically, another involves actually writing code that solves the problem in a convenient way. Someone that logically solves the problem could write either the 21-line code sample or the shorter 7-line version. Someone that can also think up a way of conveniently translating a solution to code will always come up with the shorter version under the premises that he thought up that specific solution first.

Comment form
(required)
(required, but will not be displayed)
(optional)