How many of you can still read your own code you created years ago?
46 30 Dec 2016 03:27 by u/roznak
How many of you can still read your own code you created years ago?
46 30 Dec 2016 03:27 by u/roznak
How many of you can still read your own code you created years ago?
38 comments
19 u/OhBlindOne 30 Dec 2016 04:17
Whenever I go over the stuff I wrote in my first years, it's not always that I can't read it, it's more that I don't understand why I did everything in the worst possible way...
1 u/effusive_ermine 30 Dec 2016 15:02
I still do that with code I wrote only a few months ago.
2 u/DinoRider 30 Dec 2016 16:58
In my own case I know why. My earliest code was bad because I didn‘t yet know how to logically divide code into separate, independent pieces.
It didn’t help that in my early days I was doing Windows programming. The win32 API was intentionally designed to be onerous to hinder small competitors. Any experienced programmer would build a wrapper around it for whatever he is working on. I was not experienced, so my code tended to be long sections of hard to read win32 function calls.
I also had few comments because at the time I was writing it those win32 function calls made perfect sense to me. I assumed I would still remember what they are later. Another amateur mistake.
0 u/SpottyMatt 31 Dec 2016 02:04
Many years ago, no, for the same reason - why oh why did I do that and what was I thinking!?
But somewhere just a few years ago, I can look back and I do understand what I was trying to do, and how, and why.
I think that indicates improvement!
14 u/Atarian 30 Dec 2016 03:51
I've written some pretty awful kludgy code in the past. I can read it, but it makes me wince.
I'm not saying I'm not capable of writing shitty code now, by the way.
7 u/Master_Foo 30 Dec 2016 08:57
No, that's why, over the years, I've developed some techniques that help to make code understandable.
This seems backwards, but NO comments. If code is so complicated it needs to be explained, it is a good indication that it needs to be broken up into smaller pieces. So break it up into functions and literally name that function what you would have said in the comment.
No code longer than 1 page scroll (This is a loose rule). If you can't see everything that needs to be understood on 1 page, again, it's a good indication that it needs to be broken up into logical families, like classes. Furthermore, classes can usually be broken down further into an MVC or other similar paradigm so, you aren't bombarded by unnecessary information (like the view) when you are working in the model.
Always use long descriptive variable names. Never abbreviate unless the variable is a temporary variable or an iterator. Ex. tmp, or i
Keep it bone DRY. DRY requires breaking code up. Breaking code up means descriptive class and function names. The code is literally readable because it is telling you exactly what it is doing.
2 u/roznak [OP] 30 Dec 2016 12:22
You just described how I do it :-)
2 u/iForgotMyDetails 31 Dec 2016 00:20
A weekend clean coding workshop wrapped up in one post. Props to you horse
5 u/ratsmack 30 Dec 2016 05:06
When I read mine, I begin to cry.
4 u/Lopsid 30 Dec 2016 03:33
Well the code is beautiful as always but there just aren't many comments so I have to re-understand everything. I don't know, comments make code ugly by taking up all the space... well for small programs that is. Surely there will be essays in my bigger projects.
1 u/BucktailBarry 30 Dec 2016 03:53
Yes, the need to re-understand is time-consuming. we are needs better way.
4 u/Northvvait 30 Dec 2016 06:12
I read it and am saddened by how much happier I used to be. It all used to be so much more fun.
Frameworks are all about "magic" plumbing that shuttles your data from one place to the next in a completely obscure way. All in the interest of saving you time. Of course, it ain't free, it's paid for by all the extra cruft put in place to make it all happen.
Agile is responsible for a lot of it. When you have interchangeable developers instead of people that focus on what suits them best, all of a sudden you need tools to that even the weakest database guy can get his database tasks done. Agile never fixed the mistrust between stakeholder and developer, it just tied the developer's hands. Terms like "polish the cannonball" are used to beat down and suppress the desire to do things beautifully and just turn software development into a machine in and of itself.
1 u/roznak [OP] 30 Dec 2016 12:25
Nice wording, but it is exactly that.
1 u/GainsGoblinGoebbels 31 Dec 2016 01:32
You would like this site http://programming-motherfucker.com/
0 u/Northvvait 31 Dec 2016 02:03
The "Our Values" table? That's getting framed and put on my wall.
3 u/nasalite 30 Dec 2016 05:41
Reading it is no problem, but some of the design decisions... do not necessarily reflect what I would do if I were to try it again right now. A lot of my older code was more ambitious than what I do today - I was trying things which I didn't know how to do already, so you can easily see where the grand plan wasn't fully formed yet.
3 u/PuttItOut 30 Dec 2016 08:08
I've created some fantastic messes. Wrote an ORM framework back in the day that uses the .NET CodeDom to write all logic then outputs source code files, thousands of them, which are then compiled as libraries.
Extending this is a nightmare but I have a few apps that use it exclusively for all database interaction so it lives on unfortunately.
If I need to modify an if statement in the output, finding the code that expresses this if statement is nearly impossible.
2 u/0x7a69 30 Dec 2016 05:06
2 u/netburn 30 Dec 2016 05:59
You don't read code, you read comments, and they tell you how fucked up the code below is going to be.
True coders don't bother reading code anyway, because they read the first line, decide that it's total shit, and rewrite the entire program.
2 u/wonderfulcheese 30 Dec 2016 07:04
I am embarrassed of some of my older code.
1 u/Mojomatrix 30 Dec 2016 03:54
If you count Applesoft BASIC, then, maybe
1 u/ShitsInPringlesCans 30 Dec 2016 04:35
I can because I'm extremely verbose in my coding. No shortcuts and descriptive variables and function names. Anyone can follow my code easily.
1 u/Pwning4Ever 30 Dec 2016 04:41
Kinda, my first language was Python which is a very procedural language so easy to read.
1 u/noblefool 30 Dec 2016 05:06
Depends on what phase of my own coding existence we're talking about. . . For example, my Java coding life cycle goes kind of like so: Yes up until when I got my first patterns textbook, figured out what interfaces were for and what System.Reflection was, then no until I actually figured out how NOT to use those things all of the time. . . I have quite a few "Too clever by half" implementations that look strikingly like spaghetti code in that era. . .
1 u/PlasmaDistortion 30 Dec 2016 05:20
I recently rewrote an old program of mine which was originally about 10k lines of code and is now about 600. Rewriting it took away some of the shame.
1 u/JohnQCitizen 30 Dec 2016 06:00
Most of my code is kept very simple. If there is a way that isn't exact, but close enough, and it reduces enough, I'll use it, and add the extra later. I get away with it by calling it prototyping, and my boss will usually just use the prototype and not have me dev further.
1 u/SelfReferenceParadox 30 Dec 2016 06:41
I'm at the point where it's readable, but incredibly poorly written. I've still got an algorithm I translated from Python to C about a year ago, saved just for giggles. It's a direct translation that mallocs new objects where Python created new ones, and leaks so much memory it's barely usable.
1 u/SOULESS 30 Dec 2016 08:24
I've always heavily commented my code. I think it's a chick thing. So I can always understand exactly what I was attempting to do.
1 u/NorwegianBlackMetal 30 Dec 2016 08:34
If your code today is identical as yesterdays, you aren't progressing. I have a few moments where I just change my coding style all together, it happens once or twice a year. Recent stuff shouldn't be bad but like 5 years ago yikes.
1 u/Wahaha 30 Dec 2016 20:39
I can read it alright. Understanding it is the tricky part. Depending on the language it ranges from "Alright, now I know what this code does." to ... less pleasant assessments.
1 u/GoatWorrier 30 Dec 2016 22:14
I guess everybody who didn't have a stroke? Is everybody proud of their work? That is a different question all together.
1 u/DrBunsen 03 Jan 2017 08:36
Pretty good, I write documentation in my code.
0 u/Drunkenmoba 30 Dec 2016 06:30
Easily. I comment everything.
1 u/badkangaroo 30 Dec 2016 06:49
I often read my old comments and find stuff like //fix this later. or //come up with something more clever. and then i cry, then start over.
0 u/SChalice 30 Dec 2016 06:52
If you can't then you aren't a coder.
0 u/AmaleksHairyAss 31 Dec 2016 00:02
I learned early to comment profusely. I've learned a lot about program design and algorithmic complexity, but thanks to my comments I don't have any trouble.