Jump to content

A Clear Example That Proper Form and Structure Matters

Over the summer I have been interning at a local railway company and over the course of this internship my job has been to convert old programs from VB6 to C# (no idea why they dont want VB.net) and write new tools for them to use and the tools range in function from analyzing raw track data to double checking track placement information and track design. Im supposedly the first "true" programmer they have ever hired as they said that programming these smaller tools has always been done by low level technicians that picked up coding on the fly for rapid prototyping. I got hired on since Microsoft is ending support for VB 6 and they have no one on staff that is familiar with more modern languages and standards.  

 

The problem is the companys lack of good programmers shows and not in a good way. I havent had many problems up until this point as I was mainly writing new programs from scratch, for this program in particular they said they just wanted it commented to see how it works to have it converted at a latter date by myself or someone else when i go back to school. This sent up a red flag, they have a program that they don't even know how it all even works and the original guy that wrote it left the company 5 years ago, all they know is that the program does what its supposed to do, design control line blocks for railway systems. 

 

So i went to go look at this program to dig around to see how it works and I was awestuck by what I found, no only was there no comment in sight, this program is over 20k lines long and spread across a couple files but there is not a single comment to what does what. Not a single one, this would have not been a problem as im well versed in reading code and its like reading english to me, however this might as well be scribbles on a paper as the program did not even use proper naming conventions!!!

 

Here is a segment of one of the many functions within this program. 

 

 
Private Function testfunction1(ds, x1, x2, x4, x6, t5, t6, t7, T8, T9, t10)
Dim m, i, j, j1, L2, k, k1, X, xx, x3, x5, x7, x9, x10, x11, x15, xt1, xt2, Tk2, ssss0 As Long
Dim t0, t1, t2, t3, t4, vv, sbd, vdx, vtx, XSpd, GG, G1,G2, Z77 As Single
Dim VvV() As Single
Static vd, vt, vd6, vt6, vv6  As Single
Dim mg, mg1, mg2 As String
 
This has got to win the worst code ever award, after spending 2days on this one function alone ( there are about 150 functions in total with this program) i finally figured out what it actually does, supposedly this function takes various bits of information from acceleration, grade, velocity, and so on and provides a realistic view of how a train is supposed to run and compares it with an original source file.  My problem is that NONE OF THEM ARE NAMED PROPERLY. It honestly looks like some guy sat down and just started using variable names without regards to naming them based on what they do. I mean for goodness sakes the function name is testfunction1, come on he couldn't have named it something like TrainAnalysis or something appropriate? As for the whole mass of x variables the first thing you would think would be that they are different distance variables.....NOPE some of them are Velocitys, some are Acceleration rates, Some are Gradients, Some are different Motor Torques applied. This barely even qualifys as code
 
here is another section of code from a different function, my god its completely unreadable and just punishing to even look at.
 
If (Tk2 <> x6) Then x4 = x6 - x1 + 1
            If VtStd(x4 + x2) <= VtStt(x4 + x2) Then
                t0 = VtStd(x1) + t4
            ElseIf x2 = x7 Then
                t0 = t4
            End If

 

 

Private Function testfunction47(a, Pah1, Pah2, Ahhhs() As Long, Hfactor() As Single)
Dim i, j, k, ke, kf, kk, m, x1, x2, xXxX3, X4, x5, Lunt, Toes, TkIDx As Long
Dim t, t1, cv, PP0, PPlen, t3, t4 As Single
Dim T9, SN, msg, TemName As String

 

This just makes me want to puke, the "Lunt" and "Toes" variables are stupid names as well, Lunt is basically a variable for retrieving the track design length, "Toes" is the max speed of a train on that track segment. This is just impossible.

 

 

 

Now the big dilemma is how do i even go about telling my boss that this code is so bad and so terribly written that it should just be thrown in the trash and something new should be created? To think they are trusting MULTI-MILLION DOLLAR Train Testing contracts to this program is just sickening. So how do I go about basically saying that whoever he had working on this project was a complete and total idiot and this should have never made it as a primary tool? As basically im insulting not only a former employee but a whole group of "Code Monkeys" that are supposed to maintain this program (5 people). i think this is unacceptable that this program has no structure or flow, does not make any sense with naming and does not have a single line of comments to be found. I don't want to lose my job, however I feel im between a rock and a hard place with this one program because it is so broken and such an insult to programming that it should not even be used. to think that 5 people let this slide by and said it was fine, If i was there boss I would fire them on the spot. Im just at a loss on this one, anyone have any thoughts?

Link to comment
Share on other sites

Link to post
Share on other sites

On your free time recreate the code so that others can actually understand it and maybe they will appreciate what work you put in to it, as you said there is millions of dollars riding on this previous coders disappointing work. I only recently took up Java and a bit of C# and I know at least to name stuff that makes sense and to add comments where anything might possibly need to be explained, I was looking at the code and it does not make any sense, I am glad I am not working there I wouldn't be able to rewrite that if my life depended on it.

There are 10 types of people in the world: Those who understand binary, and those who don't.

Just some helpful stuff: You're - You are, Your - Your car, They're - They are, Their - Their car, There - Over there.

 

Folding @ Home Install Guide and Links | My Build

 

Link to comment
Share on other sites

Link to post
Share on other sites

That made me want to vomit.

I needed a new bin after reading the post.

There's a time and place for everything! But not now. - Professor Oak

i7 2600K 4.3GHz  -  GTX 1060 3GB  - ASUS P8Z68-V - 16GB DDR3-1600 CL9 - EIZO 1080p 120Hz VA

Intel Skulltrail: 2x Core 2 Quad QX9775 - Intel D5400XS - 16GB FB DDR2-800 CL5 Quad Channel

EVGA SR-2 Classified - 2x Xeon X5675 4.2GHz - 24GB DDR3-1830 C10 Triple Channel

Intel Skulltrail #2: 2x Xeon E5472  - Intel D5400XS - 16GB FB DDR2-667 CL5 Quad Channel

 

 

Link to comment
Share on other sites

Link to post
Share on other sites

Ouch, that actually hurt my brain! :o

Now the big dilemma is how do i even go about telling my boss that this code is so bad and so terribly written that it should just be thrown in the trash and something new should be created?

Since I don't know your boss it's a bit tricky, but this is what comes to mind:

  • Avoid personally insulting the people responsible (calling them names etc.), but instead

    focus on how terrible the code itself is. There's no way around it, that's just a fact.

    How you phrase that (possibly softening the blow a bit and all that stuff) depends on your

    boss' personality and mood, so I can't help with that. But keep it factual, dont' make

    it personal.

  • Make it clear that it's much more expensive in the long run to maintain horrible code

    than good code.

  • Since bad code has a much higher chance of bugs and bugs can lead to unreliable results

    this code might very well be a liability for the company. Especially when adding sections

    to it or modifying existing parts the chance of a programmer misunderstanding something

    and therefore introducing a new bug is much higher than with good code (as is evident from

    how long it takes you to wade through this).

BUILD LOGS: HELIOS - Latest Update: 2015-SEP-06 ::: ZEUS - BOTW 2013-JUN-28 ::: APOLLO - Complete: 2014-MAY-10
OTHER STUFF: Cable Lacing Tutorial ::: What Is ZFS? ::: mincss Primer ::: LSI RAID Card Flashing Tutorial
FORUM INFO: Community Standards ::: The Moderating Team ::: 10TB+ Storage Showoff Topic

Link to comment
Share on other sites

Link to post
Share on other sites

On your free time recreate the code so that others can actually understand it and maybe they will appreciate what work you put in to it, as you said there is millions of dollars riding on this previous coders disappointing work. I only recently took up Java and a bit of C# and I know at least to name stuff that makes sense and to add comments where anything might possibly need to be explained, I was looking at the code and it does not make any sense, I am glad I am not working there I wouldn't be able to rewrite that if my life depended on it.

 

I would recreate the thing from scratch if i didn't have to go back to college soon, this might seem greedy and selfish but I don't work for free ( I got to eat and pay for college), to rework something of this magnitude is an enormous task in itself and is definitely not worth the $13/hr they pay me at this internship. I would have to put aside alot of my own time outside of work to rewrite something this large, even then it might take me 2 months or so because of how large and complex this program is. I would have to redo the entire front end UI from scratch as VB6 is not easily converted when it comes to windows forms. The core code would not take me too long maybe a month at max which is a small time frame considering how big this program is ( im the only one working on it :/). However fixing this kind of screwup does not come cheap, even if you hired an entire software team rewriting it would be extremely costly.

Link to comment
Share on other sites

Link to post
Share on other sites

I would recreate the thing from scratch if i didn't have to go back to college soon, this might seem greedy and selfish but I don't work for free

That is neither greedy nor selfish, it's just common sense. Living costs money, and you're

not a charity. Doing a friend a favour for free is one thing (and totally OK IMHO), but

I never do substantial work for any third party (company, relatives, neighbours etc.) for

free. As soon as somebody realizes that they can give you work and not pay you for it

you'll end up with problems. You'll end up getting exploited, and when you finally put a

stop to it and start demanding money for your services they'll act like entitles shits

("You've never asked for money before, why should I pay now?").

At least that's been my experience, maybe others have had more positive ones.

BUILD LOGS: HELIOS - Latest Update: 2015-SEP-06 ::: ZEUS - BOTW 2013-JUN-28 ::: APOLLO - Complete: 2014-MAY-10
OTHER STUFF: Cable Lacing Tutorial ::: What Is ZFS? ::: mincss Primer ::: LSI RAID Card Flashing Tutorial
FORUM INFO: Community Standards ::: The Moderating Team ::: 10TB+ Storage Showoff Topic

Link to comment
Share on other sites

Link to post
Share on other sites

In terms of the code, that is simply horrendous! I mean i'm only finished my first module in C, and even i realise how important it is to comment all your code and to keep it nicely in line and the variables well spelled.

 

Now for the predicament, I'd say talk to him! Try to bring it to his understanding with some sort of comparison or something, preferably to trains! :P

AMD 8350 // 8 GB Corsair Ram // PNY 780 Ti // Asus 1080p Monitor // Antec 120mm AIO // CM Quickfire TK w/ Custom Caps  // RAT 5 mouse // Audio Technica m50x // Behringer 4-line + Line6 8-line Audio Interfaces

Link to comment
Share on other sites

Link to post
Share on other sites

Wow, that code looks very messy.

 

With that said, am I the only one who thinks that the code almost looks computer generated.  Like an old decompiler days era, where if you lost your code base you could "recover" your code from the debug executable (which makes things look absolutely dreadful)....or compiled using a primitive obfuscation, and then decompiled back into the garbled up mess.

0b10111010 10101101 11110000 00001101

Link to comment
Share on other sites

Link to post
Share on other sites

Show them the difference between clean, understandable code (maybe convert a portion of it to C# to illustrate and place it next to the snippet of old code that does the same thing) and the garbage you have right now. If that doesn't drive the point home, nothing else will. Maybe even ask him "What do you think this piece of code is doing?" showing both the new and old code. He already doesn't know what the old code does, and if done correctly, he may be able to get the gist of the new code. Even if he can understand the gist of it, that's good enough (considering it's an impromptu question).

 

I've run into a similar situation with MATLAB code at my current internship; I needed to read data files (mostly text) and parse it and plot the data, and was given some reference files to do that. Problem was, the files were all 1000s of lines long and would have taken most of my work term to actually figure out what it was doing. I ended up just re-coding my own version and manually removing out invalid data (I'm assuming the old program is removing invalid data from the files automatically, as some of them did have useless pieces of info). I could probably code that in with a few extra lines if I absolutely needed to.

 

My entire code ended up less than 150 lines including plotting and saving/organizing the plots.

Interested in Linux, SteamOS and Open-source applications? Go here

Gaming Rig - CPU: i5 3570k @ Stock | GPU: EVGA Geforce 560Ti 448 Core Classified Ultra | RAM: Mushkin Enhanced Blackline 8GB DDR3 1600 | SSD: Crucial M4 128GB | HDD: 3TB Seagate Barracuda, 1TB WD Caviar Black, 1TB Seagate Barracuda | Case: Antec Lanboy Air | KB: Corsair Vengeance K70 Cherry MX Blue | Mouse: Corsair Vengeance M95 | Headset: Steelseries Siberia V2

 

 

Link to comment
Share on other sites

Link to post
Share on other sites

I have no idea on what I'm looking at.

Exactly, its a clear cut reason why you should use proper naming and commenting or crap like this abortion of a program happens where no one knows how or why it even works, some nutcase sat down and and slapped this program together and when it finally complied they packaged it up and said jobs done, at the time they are happy since it does everything they want, however its been a few years and they now find they want more functionality and a few bug fixes and lo and behold no one can do it as the code is completely unreadable.

 

I may be the one that has to sit down and fix this problem in the end, however I thought I would share this experience since anyone who deems them self a programmer should be willing to take note and realize why readability matters.

Link to comment
Share on other sites

Link to post
Share on other sites

I think it would be fun to get in there and clean it up nice & proper :)

Dis track?  Jesus christ why'd we even fight a war?  - Ron Cadillac

Link to comment
Share on other sites

Link to post
Share on other sites

I think it would be fun to get in there and clean it up nice & proper :)

That kind of cleaning is costly.......especially considering theres over 150 functions that are used in this one program and they all look like this. So the better question is how much is this program truly worth to you? tell me with your wallet, if you handed this off to a company to do it ( software company) they would laugh at you and charge you a ridiculous amount as it is close to unworkable. College students need money too :P

Link to comment
Share on other sites

Link to post
Share on other sites

I don't know that about coding but it looks really... messy. What language is it? Python? - or maybe I'm just lost (in translation lulz).  :ph34r:

Link to comment
Share on other sites

Link to post
Share on other sites

That kind of cleaning is costly.......especially considering theres over 150 functions that are used in this one program and they all look like this. So the better question is how much is this program truly worth to you? tell me with your wallet, if you handed this off to a company to do it ( software company) they would laugh at you and charge you a ridiculous amount as it is close to unworkable. College students need money too :P

 

Well sure, all things cost money.  That said simply as a task to accomplish cleaning it up would be satisfying.  I wasn't talking about anyone paying for it.

Dis track?  Jesus christ why'd we even fight a war?  - Ron Cadillac

Link to comment
Share on other sites

Link to post
Share on other sites

I don't know that about coding but it looks really... messy. What language is it? Python? - or maybe I'm just lost (in translation lulz).  :ph34r:

This program is in VB6 

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×