My favourite programming book.

๐ŸŽ™๏ธ DieSmarteMamba ยท 17201 points ยท Posted at 12:09:24 on March 28, 2018 ยท (Permalink)


Saved comment

lurkerfox ยท 491 points ยท Posted at 16:03:15 on March 28, 2018 ยท (Permalink)

I have the opposite problem.

"Today I'll implement the next feature on my to do list!"

> proceeds to refactor/rewrite the same working code for the fourth time because it 'doesnt feel right'

BugDeveloper ยท 273 points ยท Posted at 16:19:13 on March 28, 2018 ยท (Permalink)

"unclean, unclean!" continue scrubbing vigorously

TGameCo ยท 80 points ยท Posted at 17:06:36 on March 28, 2018 ยท (Permalink)

*foreign contaminant*

IAmDrag0n ยท 15 points ยท Posted at 23:07:50 on March 28, 2018 ยท (Permalink)

This made me laugh my ass off because thatโ€™s how I refactor. I start with one function, find out it used another, go refactor that one to be sure itโ€™s clean, then continue onwards, rinse and repeat

Extract ยท 31 points ยท Posted at 17:45:15 on March 28, 2018 ยท (Permalink)

"Anything short of perfection is irrelevant!"

ObstreperousCanadian ยท 9 points ยท Posted at 18:11:15 on March 28, 2018 ยท (Permalink)

*short

TorTheMentor ยท 11 points ยท Posted at 20:50:40 on March 28, 2018 ยท (Permalink)

Oops, I think I found some Lint.

x1WOLF101x ยท 3 points ยท Posted at 21:09:58 on March 28, 2018 ยท (Permalink)

It'll be the end of us

CrimsonMutt ยท 11 points ยท Posted at 20:42:57 on March 28, 2018 ยท (Permalink)

"dirty fucking filthy peasants UNCLEAN!"

brisk0 ยท 6 points ยท Posted at 21:48:40 on March 28, 2018 ยท (Permalink)

Out damnรฉd spot!

Belazor ยท 4 points ยท Posted at 23:20:03 on March 28, 2018 ยท (Permalink)

DELETE DELETE DELETE DELETE

binsmyth ยท 5 points ยท Posted at 03:28:41 on March 29, 2018 ยท (Permalink)

I just want to be pure.

shaantya ยท 2 points ยท Posted at 01:47:57 on March 29, 2018 ยท (Permalink)

Username probably checks out.

I love it btw.

jherazob ยท 2 points ยท Posted at 08:58:04 on March 29, 2018 ยท (Permalink)

SHAME *Ding*

WellWrittenSophist ยท 50 points ยท Posted at 16:37:42 on March 28, 2018 ยท (Permalink)

As someone who only programs as a hobby, mainly making small tools to help with my work, constant refactoring is my life.

I rewrite compulsively. I taught myself because I enjoyed doing programming challenges and puzzles, so while I may feel competent in the mechanics of the language... I know jackshit about design practice which feels like the only part that really matters.

I think I have rewritten this simple thing to scrape our intranet and report some information to me a dozen times for no real reason. I just keep reshaping things whenever some new style or idea pops into my head.

Audiblade ยท 68 points ยท Posted at 17:06:29 on March 28, 2018 ยท (Permalink)

Here's the thing: By doing this, you are learning a lot about how different approaches to the same problem affect how easy or difficult your code is to work with in different situations. You might not know much about design now, but you're learning design in the most real and worthwhile way possible.

CrimsonMutt ยท 5 points ยท Posted at 20:48:31 on March 28, 2018 ยท (Permalink)

I like when i learn a new trick in a language and for the next few days just look for places to use that approach.

I love that i can just track style changes over months of my commits. Like the time i tried declaring Task/Action variables as inner functions in C# wherever i could to see how useful it is.

lurkerfox ยท 22 points ยท Posted at 17:07:38 on March 28, 2018 ยท (Permalink)

I wonder if this is a more common issue for hobby programmers cause you pretty much described my exact reasoning and I'm just programming on the side cause I enjoy it.

I'm obsessed with trying to make sure I do things the idiomatic way for the language. So I'm changing the code around a lot to better fit some principal of the language. I do legitimately feel like each iteration is an improvement on the last but there's that voice in the back of my head that says I really should have moved on by now if I wanted my project to ever be 'done'.

antonivs ยท 15 points ยท Posted at 18:40:47 on March 28, 2018 ยท (Permalink)

I'm obsessed with trying to make sure I do things the idiomatic way for the language.

Sometimes that's not the right thing to do. Languages typically offer many ways to do things, and it can make more sense to fit the solution to the problem without injecting idioms that may not really be relevant.

lurkerfox ยท 4 points ยท Posted at 20:34:39 on March 28, 2018 ยท (Permalink)

You're not wrong, but for me personally if I allow myself to do that without a lot of strong consideration I'll get into a trap where I'm using a language totally outside of how it's intended and the code becomes garbage.

btaz ยท 12 points ยท Posted at 20:30:00 on March 28, 2018 ยท (Permalink)

I rewrite compulsively. I taught myself because I enjoyed doing programming challenges and puzzles, so while I may feel competent in the mechanics of the language... I know jackshit about design practice which feels like the only part that really matters.

You may not know this but you are qualified for a programming job.

gawalls ยท 3 points ยท Posted at 21:11:12 on March 28, 2018 ยท (Permalink)

You're probably using a lot of well know patterns without even realising it - a lot are common sense but if not - so what if it works

Iceman_259 ยท 2 points ยท Posted at 01:42:54 on March 29, 2018 ยท (Permalink)

Not to mention dogmatically following design patterns often leads to massive amounts of kludge and a generally hard-to-follow codebase a lot of the time.

gawalls ยท 1 points ยท Posted at 06:04:30 on March 29, 2018 ยท (Permalink)

Your not wrong, someone's people refactor just for the sake of it - I'm a massive fan of the gang of four and I do use the repository pattern a lot at work because we have several split databases but in my opinion it often goes too far.

iLikeStuff77 ยท 5 points ยท Posted at 22:28:42 on March 28, 2018 ยท (Permalink)

Not sure if it helps, but this website is a great starting point when looking into design patterns.

It even has a section for "anti patterns" which are basically symptoms of a bad design.

I found it incredibly useful when I started seriously programming.

WellWrittenSophist ยท 1 points ยท Posted at 23:29:04 on March 30, 2018 ยท (Permalink)

It's been a bit, but wanted to drop in and say that this website has been really helpful and made clear a lot of things that been big blind spots for me.

iLikeStuff77 ยท 1 points ยท Posted at 00:13:44 on March 31, 2018 ยท (Permalink)

I'm glad it helped! I found it really nice for concisely describing why code "felt" off or well designed.

Extract ยท 2 points ยท Posted at 17:44:48 on March 28, 2018 ยท (Permalink)

Imperfection must be reshaped!

Neuromante ยท 710 points ยท Posted at 14:41:10 on March 28, 2018 ยท (Permalink)

//TODO

omlette_du_chomage ยท 265 points ยท Posted at 17:44:03 on March 28, 2018 ยท (Permalink)

The next guy will at least know you had good intentions and were aware of the problem ๐Ÿ˜…

Piyh ยท 152 points ยท Posted at 17:48:38 on March 28, 2018 ยท (Permalink)

TODO: Fix my sham of a life

egotisticalnoob ยท 53 points ยท Posted at 18:48:55 on March 28, 2018 ยท (Permalink)

TODO: End my sham of a life

VileDevastation ยท 21 points ยท Posted at 19:23:50 on March 28, 2018 ยท (Permalink)

The sham and not your life, right?

egotisticalnoob ยท 24 points ยท Posted at 19:25:29 on March 28, 2018 ยท (Permalink)

Oh, sure. Either way is fine.

willworth ยท 15 points ยท Posted at 19:50:12 on March 28, 2018 ยท (Permalink)

It's rarely necessary to throw away the whole codebase. Just look at Netscape. I'm here to talk if you want help "refactoring" things.

TH3_ST0CK ยท 7 points ยท Posted at 21:18:37 on March 28, 2018 ยท (Permalink)

cout << 'Goodbye World!\n';

READTHISCALMLY ยท 3 points ยท Posted at 22:57:54 on March 28, 2018 ยท (Permalink)

return 0;

APimpNamedAPimpNamed ยท 2 points ยท Posted at 03:05:50 on March 29, 2018 ยท (Permalink)

Void

aroswift ยท 1 points ยท Posted at 01:18:46 on March 29, 2018 ยท (Permalink)

Aware of a problem

Okichah ยท 26 points ยท Posted at 19:41:42 on March 28, 2018 ยท (Permalink)

I was especially happy when i did a global search for TODO and saw comments in third party apps and jquery.

Made me proud to be a fellow procrastinator.

oweiler ยท 18 points ยท Posted at 19:08:04 on March 28, 2018 ยท (Permalink)

//TODO: Never

cribsbogaards ยท 8 points ยท Posted at 20:53:03 on March 28, 2018 ยท (Permalink)

//TODO write a book full of hilarious programmer jokes

zomBitch89 ยท 7 points ยท Posted at 21:40:33 on March 28, 2018 ยท (Permalink)

My oop professor actually has one, I'd tell you more but I refuse to pay 40 dollars to his arrogant ass to know more about it

wllmsaccnt ยท 5 points ยท Posted at 00:16:01 on March 29, 2018 ยท (Permalink)

Pragmatic Object Oriented Programming for Back End Developing - Written By zoomBitch89's Professor

JuhaJGam3R ยท 1 points ยท Posted at 21:47:02 on March 28, 2018 ยท (Permalink)

Lmao

thebryguy23 ยท 3 points ยท Posted at 22:38:34 on March 28, 2018 ยท (Permalink)
//TEMP TEMP TEMP

Actual comment in my company's codebase, been there for at least the two years I've been there...but too lazy to bother looking up the blame in git

bass-lick_instinct ยท 1 points ยท Posted at 14:00:11 on March 29, 2018 ยท (Permalink)

I worked for a company once where someone was trying various versions of the same stored procedure until one finally stuck, at least I think that's what they were doing. The DB had

SPROC_CreateNewFile_TEST

SPROC_CreateNewFile_TEST_TEST 

SPROC_CreateNewFile_TEST_TEST_TEST

...etc (if they were going this route, why they didn't just call them _TEST2, _TEST3, etc I have no idea).

In any case, if I remember correctly, the production version was:

SPROC_CreateNewFile_TEST_TEST_TEST_TEST_TEST_TEST_TEST
MusgraveMichael ยท 1 points ยท Posted at 00:14:04 on March 29, 2018 ยท (Permalink)

I still find 6-7 year old todos in my companyโ€™s code.

vgf89 ยท 1 points ยท Posted at 01:37:46 on March 29, 2018 ยท (Permalink)

Oh god

Mwakay ยท 0 points ยท Posted at 22:31:17 on March 28, 2018 ยท (Permalink)

Wow I actually DID something written in a TODO I left, just today ! ... well it was required for my new code to compile properly. But still !

SuperSpartan177 ยท 0 points ยท Posted at 23:49:58 on March 28, 2018 ยท (Permalink)

What does that even mean? i always it on NetBeans but delete it.

Neuromante ยท 1 points ยท Posted at 07:42:29 on March 29, 2018 ยท (Permalink)

I hope you are trying to troll, in case you don't, comment tags

SuperSpartan177 ยท 1 points ยท Posted at 16:15:32 on March 29, 2018 ยท (Permalink)

Not even joking, sorry about the bad English before. Im still learning java, thought that it meant something more than that but I guess not, teach never explained it.

Neuromante ยท 1 points ยท Posted at 16:24:43 on March 29, 2018 ยท (Permalink)

Oh, then if you are being serious, take into account that most modern IDE's actually scan the code for these tags and shows them in "taks" tabs. Quite useful on big projects to find your way around old stuff you left "to fix on a more relaxed day."

SuperSpartan177 ยท 1 points ยท Posted at 16:59:01 on March 29, 2018 ยท (Permalink)

okay didn't know about that thanks, really good feature to have.

[deleted] ยท 0 points ยท Posted at 23:59:03 on March 28, 2018 ยท (Permalink)

[deleted]

SuperSpartan177 ยท 1 points ยท Posted at 16:58:44 on March 29, 2018 ยท (Permalink)

I thought it meant more than that but glad to know I was just over thinking it

rubenduiveman ยท 755 points ยท Posted at 13:08:52 on March 28, 2018 ยท (Permalink)

Currently refactoring code I wrote earlier today. So proud.

๐ŸŽ™๏ธ DieSmarteMamba ยท 380 points ยท Posted at 13:12:27 on March 28, 2018 ยท (Permalink)

Shh, quiet. You're ruining my joke ;}

keiron249 ยท 276 points ยท Posted at 18:52:01 on March 28, 2018 ยท (Permalink)

ERROR: Unexpected character '}'

Dankunderscorememes ยท 29 points ยท Posted at 22:10:24 on March 28, 2018 ยท (Permalink)

That made my blood pressure spike

mastermindxs ยท 15 points ยท Posted at 22:43:33 on March 28, 2018 ยท (Permalink)

My beeper went off what's going on

man4160 ยท 7 points ยท Posted at 22:40:49 on March 28, 2018 ยท (Permalink)

I'll fix it later today don't worry

PM_ME_A_WEBSITE_IDEA ยท 3 points ยท Posted at 00:16:12 on March 29, 2018 ยท (Permalink)

I swear to god I saw this 50 times today because apparently I never remember to add commas to my objects :l

jeffsterlive ยท 1 points ยท Posted at 18:45:36 on March 29, 2018 ยท (Permalink)

ERROR: Unexpected character '}'

token

keiron249 ยท 21 points ยท Posted at 18:52:09 on March 28, 2018 ยท (Permalink)

ERROR: Unexpected character '}'

Edit: oh shit, I hate the Reddit mobile app sometimes

[deleted] ยท 47 points ยท Posted at 20:19:56 on March 28, 2018 ยท (Permalink)

[deleted]

keiron249 ยท 23 points ยท Posted at 20:21:24 on March 28, 2018 ยท (Permalink)

Never noticed until I saw your comment, thanks!

minion_is_here ยท 12 points ยท Posted at 20:38:07 on March 28, 2018 ยท (Permalink)

You know you can delete comments

frustratinbubble ยท 5 points ยท Posted at 20:38:17 on March 28, 2018 ยท (Permalink)

don't tell me how to live my life

BloodRainOnTheSnow ยท 3 points ยท Posted at 20:44:17 on March 28, 2018 ยท (Permalink)

As in all the time. And it gets confused when you link a comment on a page thats too long. And it obnoxiously scrolls to the top after expanding a comment tree. Not to mention the once a day crashes. Its a piece of crap.

micwallace ยท 2 points ยท Posted at 21:46:41 on March 28, 2018 ยท (Permalink)

If youโ€™re on Android try my app, Reddinator :-D

[deleted] ยท 1 points ยท Posted at 02:09:16 on March 29, 2018 ยท (Permalink)

[deleted]

sneakpeekbot ยท 2 points ยท Posted at 02:09:20 on March 29, 2018 ยท (Permalink)
DracoCharky ยท 3 points ยท Posted at 23:09:18 on March 28, 2018 ยท (Permalink)

It's ok now I can upvote you twice

maverickgxg ยท 57 points ยท Posted at 14:27:12 on March 28, 2018 ยท (Permalink)

me too actually :) ok ok, the code was written yesterday in the evening. still cleaning day today :D

retepred ยท 40 points ยท Posted at 15:17:17 on March 28, 2018 ยท (Permalink)

Me too!

Ok ok, the code I wrote earlier didnโ€™t work.

2Punx2Furious ยท 46 points ยท Posted at 15:27:15 on March 28, 2018 ยท (Permalink)

I'm refactoring code I wrote months ago. It's horrible.

It's nice that it looks like I've improved quite a bit though.

Mouaijin ยท 61 points ยท Posted at 16:32:13 on March 28, 2018 ยท (Permalink)

Man you're going to feel like an idiot for saying that in a few months.

[deleted] ยท 26 points ยท Posted at 16:44:18 on March 28, 2018 ยท (Permalink)

He is going to feel like he improved even more

2Punx2Furious ยท 9 points ยท Posted at 17:01:41 on March 28, 2018 ยท (Permalink)

Yeah, hopefully ahah

Wouldn't want to stagnate.

lkh23o874249plhkjhdl ยท 12 points ยท Posted at 17:44:37 on March 28, 2018 ยท (Permalink)

Youโ€™ll think you have a good design until you realize it sucks. Thatโ€™s how you learn post-refactor haha. Repeat until your classes and methods and tiny and boring and do nothing...thatโ€™s when youโ€™ve made it dawg.

wotanii ยท 16 points ยท Posted at 17:50:14 on March 28, 2018 ยท (Permalink)

then you look at your tiny classes and think "did I really just spent 2 month on creating this little thing? It looks like something someone could have done a half a day."

2Punx2Furious ยท 11 points ยท Posted at 18:47:12 on March 28, 2018 ยท (Permalink)

Oh yeah! I've simplified something to like 50% of its original lines of code, and it looked so simple compared to before, and it was even more efficient and faster.

wotanii ยท 11 points ยท Posted at 19:39:09 on March 28, 2018 ยท (Permalink)

it literally took me years to realize, that this is the mark of a good programmer: to produce simple code.

2Punx2Furious ยท 3 points ยท Posted at 19:47:23 on March 28, 2018 ยท (Permalink)

I think that sometimes it might be counterproductive to think like that though.

Sometimes I have solutions to problems, but I don't implement them because they seem too "convoluted", and I want to try to find a simpler solutions, so I can end up losing some time doing that, but I don't know, maybe it's not lost time?

RougeRedWired ยท 3 points ยท Posted at 22:36:25 on March 28, 2018 ยท (Permalink)

Nope it's not lost time, i am going through that too. I realised that once you have fou d those simpler ways, you implement them whenever you get the chance. In the end finding any given simpler solution for any given problem may help you write better code in the futur as well and improve your unddrstanding of the language you use? A good example for me has been cutting away unnecessary variables or leaving out loops in dataframes.

wotanii ยท 2 points ยท Posted at 20:20:41 on March 28, 2018 ยท (Permalink)

It's only lost time if you stop working with this technology after this. Otherwise spending time today on understanding the system will speed up your work tomorrow by a margin (we are talking >200% here).

And as a bonus you'll make yourself more valuable (by being more proficient) and you leave quality code for your company and --most importantly-- you'll be proud of your work.

2Punx2Furious ยท 2 points ยท Posted at 21:27:54 on March 28, 2018 ยท (Permalink)

Good points, makes me feel better about the time I spend trying to come up with better solutions.

rJohn420 ยท 1 points ยท Posted at 00:34:40 on March 29, 2018 ยท (Permalink)

What do you mean by โ€˜simpleโ€™ code?

To make the code easier to debug and to read I always try to wrap blocks of code into fancy methods that allow for greater abstraction (I use Java).

Is this the correct way to go?

wotanii ยท 1 points ยท Posted at 06:21:56 on March 29, 2018 ยท (Permalink)

when you read someone else's code and everything is obvious. And at every line you think "well of course, how else would you do this?". It's the opposite of "wtf per minute"

The best/simplest code I have ever seen was from a senior dev at my old job. He was 2 years past retirement and worked with the frame-work from the very beginning. I could scroll past the lines and immediately understood what each line did.


Is this the correct way to go?

I think it's really really hard to learn this. Above all you must spend lots of time with other people's code, so you learn to discern good from bad practices. But it's also important to make good design decisions. You can't write good code when your framework doesn't allow it. And to have a good design, you must have good requirements. And this is the hard part. Because you only get good requirements when you stand up to the management and tell them when their ideas are bad. And to do so you must either give them a viable alternative, or make a very good case about why that would be bad.

Good code requires code programmers, good architects and good management.

aiij ยท 20 points ยท Posted at 19:00:11 on March 28, 2018 ยท (Permalink)

"What idiot wrote this garbage?"

:: checks git blame ::

"Derp, look how much I've improved!"

amiuhle ยท 9 points ยท Posted at 19:18:57 on March 28, 2018 ยท (Permalink)

The only thing worse than your coworker's source code is your own source code from 6 months ago.

[deleted] ยท 3 points ยท Posted at 19:42:05 on March 28, 2018 ยท (Permalink)

[deleted]

TheRealMcTurkey ยท 3 points ยท Posted at 22:48:26 on March 28, 2018 ยท (Permalink)

2Punx2Furious -> The Glass Looks Half Full

Mouaijin -> The Glass Looks Half Empty

Clearly, the glass needs to be refactored.

BloodRainOnTheSnow ยท 10 points ยท Posted at 20:55:31 on March 28, 2018 ยท (Permalink)

Try refactoring code because you had no idea why you added that one weird section of code. Spend next few hours redoing code and patting yourself on the back over how much cleaner and faster the code is going to be. Four hours in you hit a snag and realize exactly why that code was there in the first place. Git reset and sneak to the bathroom to snort a point of heroin and question where your life went wrong...

2Punx2Furious ยท 6 points ยท Posted at 21:31:48 on March 28, 2018 ยท (Permalink)

Try refactoring code because you had no idea why you added that one weird section of code.

At the time I knew what I was doing, but now I just know there are better ways.

For example, I was getting data with subscriptions that listened for data changes, and were slower and unnecessary than just getting the data right away, but I didn't even know that was possible at the time.

Four hours in you hit a snag and realize exactly why that code was there in the first place

But yes, I've also done exactly that ahah. Thankfully it didn't take me four hours to realize that the changes I made broke everything, because it was supposed to be that way.

to snort a point of heroin

Well, except that part.

RougeRedWired ยท 3 points ยท Posted at 22:38:06 on March 28, 2018 ยท (Permalink)

Wouldn't comment help with that?

2Punx2Furious ยท 1 points ยท Posted at 23:05:40 on March 28, 2018 ยท (Permalink)

In theory.

But sometimes I'm just stupid and I change things without reading the comments I wrote.

Retbull ยท 1 points ยท Posted at 03:11:18 on March 29, 2018 ยท (Permalink)

No never I always remember why I wrote my code the way I did. I also use abv. for method names and single letters for my variables to save space on the screen... OK shit giving myself a heart attack here.

boatinwater ยท 10 points ยท Posted at 17:04:35 on March 28, 2018 ยท (Permalink)

You're commenting on Reddit though. Good joke

jbwmac ยท 5 points ยท Posted at 19:04:33 on March 28, 2018 ยท (Permalink)

Everyone knows redditing is permitted while compiling and pooping:

boatinwater ยท 1 points ยท Posted at 19:07:19 on March 28, 2018 ยท (Permalink)

Shit I forgot.

IrishWilly ยท 2 points ยท Posted at 23:46:14 on March 28, 2018 ยท (Permalink)

I spent all week 'refactoring' code. By refactoring I mean the client decided on a completely retarded coding standard and now I have to fuck up code that was working fine because there are too many if statements.. IN A TEST SUITE.

An idiot refactoring your code is the worst thing ever.

rubenduiveman ยท 1 points ยท Posted at 04:55:13 on March 29, 2018 ยท (Permalink)

But why does the client see your code!?

IrishWilly ยท 2 points ยท Posted at 05:19:14 on March 29, 2018 ยท (Permalink)

Sub contracted to build the testing system for their internal developers. Reminds me why I prefer to work alone.

rubenduiveman ยท 2 points ยท Posted at 05:57:49 on March 29, 2018 ยท (Permalink)

You donโ€™t like helping people ๐Ÿ˜

Extract ยท 1 points ยท Posted at 17:33:31 on March 28, 2018 ยท (Permalink)

I'm currently refactoring code I'm currently working on. But once I haven't worked on it for a while? Yeah, sure, I'll refactor that.. Later some day...

jbwmac ยท 1 points ยท Posted at 19:03:41 on March 28, 2018 ยท (Permalink)

The prophecies are true!

DrFloyd5 ยท 1 points ยท Posted at 02:21:17 on March 29, 2018 ยท (Permalink)

I love refactoring code. I love removing code.

Code that doesnโ€™t exist has no bugs.

saphire121 ยท 182 points ยท Posted at 13:09:18 on March 28, 2018 ยท (Permalink)

Things I'll hope the compiler optimized for 100

thipp ยท 37 points ยท Posted at 18:55:02 on March 28, 2018 ยท (Permalink)

I wish there was a way to tell what the compiler optimized. Like it could print out the source code corresponding to its optimized version.

Then you just copy paste that in there and your co-workers will be impressed by your efficient algorithms.

astraycat ยท 56 points ยท Posted at 19:10:21 on March 28, 2018 ยท (Permalink)

Generally, compiler optimizations aren't the sort of thing you would do by hand, and would inspire fear and loathing rather than impressing your coworkers. The code likely wouldn't be readable or maintainable.

thipp ยท 70 points ยท Posted at 19:17:18 on March 28, 2018 ยท (Permalink)

There's a term for writing unreadable, efficient code: job security

astraycat ยท 28 points ยท Posted at 19:19:14 on March 28, 2018 ยท (Permalink)

Volume 4

Job Security: How to Hate What You Do

NotAnonymousAtAll ยท 14 points ยท Posted at 21:43:12 on March 28, 2018 ยท (Permalink)

Then you just copy paste that in there and your co-workers will be impressed by your efficient algorithms annoyed because you wrote something in a way that is less readable than it could be, even though the compiler will optimize that stuff anyway.

Dameon_ ยท 2 points ยท Posted at 03:54:48 on March 29, 2018 ยท (Permalink)

"Oh wow, look at how this guy cached this reference to List.Count in his for loop rather than calling it every time. I'm so impressed."

iaanus ยท 61 points ยท Posted at 13:17:47 on March 28, 2018 ยท (Permalink)

I wonder what's in the first two volumes...

๐ŸŽ™๏ธ DieSmarteMamba ยท 219 points ยท Posted at 14:17:31 on March 28, 2018 ยท (Permalink)

"I don't have to comment that line, it's self-explanatory"

you_can_be_both ยท 148 points ยท Posted at 15:11:39 on March 28, 2018 ยท (Permalink)

"O(n2) is fine here, using a better algorithm would be a premature optimization."

"I don't need a library for this, rolling my own would only take a few hours."

"I'm sure this regular expression will completely sanitize all possible input, no matter how malicious."

"The PM said this requirement won't change so I'll just hard code it."

"I do template meta-programming because it improves my productivity, not because its fun."

"I'm sure this table will never have more than a few hundred rows of data."

03475638322863527 ยท 57 points ยท Posted at 18:50:57 on March 28, 2018 ยท (Permalink)

there are opposite cases too.

  • Carefully write code so that it will work correctly regardless of byte order.

  • Proceed to only compile it on x86 architecture for 25 years

solar_compost ยท 50 points ยท Posted at 19:45:59 on March 28, 2018 ยท (Permalink)

"I don't need a library for this, rolling my own would only take a few hours."

Hello darkness my old friend.

append_slash_s ยท 1 points ยท Posted at 21:49:23 on March 29, 2018 ยท (Permalink)

It's a delicate between not reinventing the wheel and staying low on dependencies.

Jetbooster ยท 49 points ยท Posted at 14:45:44 on March 28, 2018 ยท (Permalink)

"If I have to add one more function I'll make sure to break some of this program into a seperate file"

700 lines later...

Extract ยท 24 points ยท Posted at 17:48:14 on March 28, 2018 ยท (Permalink)

"If I add another function to this class, will it break this build?"

"It will be extremely painful to work with.."

"You're a big class."

".. for you."

Jetbooster ยท 7 points ยท Posted at 17:57:01 on March 28, 2018 ยท (Permalink)

I was wondering what would break first...

Your inner, or your outer loop?

KyleTheBoss95 ยท 2 points ยท Posted at 00:05:39 on March 29, 2018 ยท (Permalink)

Hey look, it me

steviestickman ยท 23 points ยท Posted at 14:34:56 on March 28, 2018 ยท (Permalink)

I wil know what i wrote when i refactor this

[deleted] ยท 9 points ยท Posted at 15:17:44 on March 28, 2018 ยท (Permalink)

I will have to say most of the code I've written or read had been pretty self explanatory. Everyone here says you need to comment all the time but it's usually just the optimized stuff or completely retarded business rules that need comments.

IndigoMontigo ยท 25 points ยท Posted at 17:16:29 on March 28, 2018 ยท (Permalink)

Comments sometimes lie.

Code never lies.

[deleted] ยท 9 points ยท Posted at 17:24:12 on March 28, 2018 ยท (Permalink)

So true. Even comments that were originally accurate can become obsolete with library or framework changes.

APimpNamedAPimpNamed ยท 1 points ยท Posted at 03:07:38 on March 29, 2018 ยท (Permalink)

But frequently obfuscates

BugDeveloper ยท 11 points ยท Posted at 16:20:55 on March 28, 2018 ยท (Permalink)

I agree. I like Uncle Bob's take on comments: use them when you fail to express yourself in code.

antonivs ยท 10 points ยท Posted at 18:44:57 on March 28, 2018 ยท (Permalink)

The corollary to this is, when you find yourself needing to write a comment, think about why you failed to express yourself in code, and whether there's a way to lift that information into the code.

At the most granular level, I often see people writing code like:

// <explanation of parts of an expression> <some long, complex expression with many parts>

...where just breaking up the expression over multiple lines with the parts named with explanatory variable names eliminates the need for the comment, and makes the code much more easily comprehensible.

The same logic applies to long methods, big classes, etc.

BugDeveloper ยท 7 points ยท Posted at 19:18:49 on March 28, 2018 ยท (Permalink)

agreed. Another hot tip from Bob was to shoot for functions that are only 3 to 5 lines. Then the function name is basically your comment. That tip has had the biggest impact on my code so far.

klparrot ยท 8 points ยท Posted at 22:07:57 on March 28, 2018 ยท (Permalink)

Ugh, it's a pain to debug, though, because of the nested calls, you're jumping in and out of scopes and it becomes harder to see it as one big picture.

IceSentry ยท 3 points ยท Posted at 22:35:03 on March 28, 2018 ยท (Permalink)

I'm fine with a function being the size of the screen but nothing more. 3 to 5 is way too small sometimes and might lead to unneeded abstraction that makes the code maybe easier to read but harder to understand what actually happens

BugDeveloper ยท 2 points ยท Posted at 01:03:33 on March 29, 2018 ยท (Permalink)

I can see that. I rarely achieve such small functions myself. Another point was that all the functions inside a function should be at the same level of abstraction, which I think would help with comprehensibility. I think the goals of writing small functions were to ensure functions only have a single responsibility, as well as making it easier to write unit tests for them.

hermionebutwithmath ยท -6 points ยท Posted at 16:24:42 on March 28, 2018 ยท (Permalink)

Either you're delusional or you've never written code longer than 20 lines.

[deleted] ยท 9 points ยท Posted at 17:19:23 on March 28, 2018 ยท (Permalink)

Lol. I've written plenty of code and maintained it for years. It sounds like you're new and have never learned how to write readable code.

QueenOliviaTheBike ยท 9 points ยท Posted at 19:06:11 on March 28, 2018 ยท (Permalink)

Or she just writes code for a different purpose or in a different language than you do. Well structured Java code with good naming can get by just fine without comments, but heaven help you if you don't put anything descriptive in the middle of some C++ OpenGL syntax nightmare.

[deleted] ยท 1 points ยท Posted at 19:42:55 on March 28, 2018 ยท (Permalink)

[deleted]

QueenOliviaTheBike ยท 1 points ยท Posted at 22:16:19 on March 28, 2018 ยท (Permalink)

And you'll notice I didn't say optimization. I'm talking about highly algorithmic mathy stuff or OpenGL setup that requires a lot of low-level setup library function calls whose names are not terribly descriptive of what they actually do.

stolencatkarma ยท 1 points ยท Posted at 19:44:52 on March 28, 2018 ยท (Permalink)

"I know what the function kv() does what does it matter?"

kc311man ยท 11 points ยท Posted at 18:32:29 on March 28, 2018 ยท (Permalink)

"I'll write unit tests tomorrow."

fonaldoley91 ยท 3 points ยท Posted at 19:39:34 on March 28, 2018 ยท (Permalink)

I'm a tester. Can 100% confirm that this is true. Along with 'we smoke tested it'.

TheLiGod ยท 0 points ยท Posted at 21:39:49 on March 28, 2018 ยท (Permalink)

I got the joke lol

Antrikshy ยท 0 points ยท Posted at 17:55:15 on March 28, 2018 ยท (Permalink)

First one volume...

ARC-7271 ยท 8 points ยท Posted at 19:19:00 on March 28, 2018 ยท (Permalink)

Arrays start at one?

Antrikshy ยท 0 points ยท Posted at 19:35:50 on March 28, 2018 ยท (Permalink)

-_-

LittlePinkRobin ยท 22 points ยท Posted at 12:40:48 on March 28, 2018 ยท (Permalink)

I have already said that about my code today

SecretlySpiders ยท 15 points ยท Posted at 15:37:52 on March 28, 2018 ยท (Permalink)

Good to see a meme economy meme hit it big. Glad I bought early

๐ŸŽ™๏ธ DieSmarteMamba ยท 8 points ยท Posted at 16:18:03 on March 28, 2018 ยท (Permalink)

I saw potential ;)

Carl_Byrd ยท 11 points ยท Posted at 16:40:31 on March 28, 2018 ยท (Permalink)

I've been meaning to refactor this one web app for 4 years.

mattmu13 ยท 12 points ยท Posted at 18:23:26 on March 28, 2018 ยท (Permalink)

I'm leaving my current job and training the others on how the software works while working through a change request so they can see how it all works (and how the code is updated).

I keep coming across things that I tell them I want to refactor, or areas that can be streamlined, etc.

I just don't have the time due to the list of other jobs I have to do.

At least once one of them had said "why did you do it that way when you could have done X".

It's interesting...

antlife ยท 6 points ยท Posted at 02:24:08 on March 29, 2018 ยท (Permalink)

Sometimes it seems like every programmer thinks every programmer is shit and does things the wrong way.

mattmu13 ยท 2 points ยท Posted at 08:29:31 on March 29, 2018 ยท (Permalink)

...and at the same time we think we're shit and everyone else is better at programming than us.

It's a weird catch 10110 situation ;-p

Arancaytar ยท 6 points ยท Posted at 20:29:30 on March 28, 2018 ยท (Permalink)

Hey, I refactor code all the time! Usually when I have an urgent deadline for something completely unrelated to that code.

selectgt ยท 1 points ยท Posted at 00:05:31 on March 29, 2018 ยท (Permalink)

Too true. I never do this all of the time, just usually.

caffeinedrinker ยท 6 points ยท Posted at 19:14:57 on March 28, 2018 ยท (Permalink)

poorly optimised code drives me insane ... i once got a routine that took hours to complete down to < 3 min ... that was sooooooo satisfying :D

Time4Boom ยท 6 points ยท Posted at 22:16:54 on March 28, 2018 ยท (Permalink)

When your intern turns simple O(1) into O(2n ) and you have to refactor everything.

[deleted] ยท 2 points ยท Posted at 22:22:33 on March 28, 2018 ยท (Permalink)

[deleted]

Time4Boom ยท 3 points ยท Posted at 22:54:08 on March 28, 2018 ยท (Permalink)

I don't have a specific algorithm, but just think about how much time you are spending on one operation with a given set of data and how much time it takes if you increase/decrease your data. Do you really need to execute certain functions on all your existing users (O(n) -> linear growth) or do you only need to account for a fixed data set (O(1) -> takes fixed time). Usually the complexity of your O depends on how many loops you have.

3_red_5_orange ยท 4 points ยท Posted at 23:07:57 on March 28, 2018 ยท (Permalink)

Pick up a book on the algorithm optimization, or algorithms in general. They'll explain all the big O stuff.

takes_joke_literally ยท 6 points ยท Posted at 20:08:44 on March 28, 2018 ยท (Permalink)

I never refactor. It amuses me to look at code that's years old with variable names that only I could have named. Lots of boops beeps bops, spizzows, badinks, snurps, etc.

Coworker loves to use -inator as a suffix in all of his function definitions.

getDimensionInator(you int, get int, the string, idea bool)
{
    //serious-ass boopin' goin' on, I tell ya hwat
}
thewurstunicorn ยท 3 points ยท Posted at 18:02:14 on March 28, 2018 ยท (Permalink)

Does this edition have the one about the team that follows agile?

LordZikarno ยท 3 points ยท Posted at 18:05:29 on March 28, 2018 ยท (Permalink)

And that is how legacy code remains shit.

lank3y ยท 2 points ยท Posted at 19:50:02 on March 28, 2018 ยท (Permalink)

however some thirty year old stuff is just plain awesome.

creativeMan ยท 3 points ยท Posted at 18:41:46 on March 28, 2018 ยท (Permalink)

I laughed aloud at first but, the sad, depressing truth dawned on me that I will in fact never refactor that code and it's going to suck forever which sunk the smile on my face.

goldfishpaws ยท 3 points ยท Posted at 19:24:29 on March 28, 2018 ยท (Permalink)

Those regular expressions that kept you awake at night will keep your successor awake at night :)

Wizywig ยท 3 points ยท Posted at 19:16:51 on March 28, 2018 ยท (Permalink)

"this is incredibly unlikely to happen in any practical scenario"

"nobody is gonna fuck it up at 2am"

Artanisx ยท 3 points ยท Posted at 19:35:26 on March 28, 2018 ยท (Permalink)

I love refactoring :p

Ghost_In_A_Jars ยท 3 points ยท Posted at 19:56:14 on March 28, 2018 ยท (Permalink)

And here I was thinking arrays start at 1 when its clearly 2.

chipstastegood ยท 3 points ยท Posted at 20:02:14 on March 28, 2018 ยท (Permalink)

Started using CodeClimate recently. Itโ€™s been very satisfying seeing code quality increase from a B or a C up to an A

scampiuk ยท 3 points ยท Posted at 20:30:45 on March 28, 2018 ยท (Permalink)

Genuine LOL

raba930 ยท 2 points ยท Posted at 18:47:20 on March 28, 2018 ยท (Permalink)

I regret nothing

xpanta ยท 2 points ยท Posted at 19:41:40 on March 28, 2018 ยท (Permalink)

I cannot not upvote this.

cbbuntz ยท 2 points ยท Posted at 20:40:26 on March 28, 2018 ยท (Permalink)

Nah, I'll just copy and paste the functions and append new or newnew to all the names. If you're lucky I'll just copy, paste and comment out the old version.

grungebot5000 ยท 2 points ยท Posted at 22:27:19 on March 28, 2018 ยท (Permalink)

refactoring isnโ€™t a process, itโ€™s a state of mind

Legin_666 ยท 2 points ยท Posted at 00:12:15 on March 29, 2018 ยท (Permalink)

what does refactor mean

vinsuper ยท 1 points ยท Posted at 15:56:34 on March 28, 2018 ยท (Permalink)

I just told this to myself today T T

TheBumpAndRub ยท 1 points ยท Posted at 17:33:54 on March 28, 2018 ยท (Permalink)

Comment that it needs refactoring. So when it breaks, the next person thinks you were just busy at the time.

AlfredoOf98 ยท 1 points ยท Posted at 18:29:10 on March 28, 2018 ยท (Permalink)

I really wish to know if there is actually such a book

Jesus_Harold_Christ ยท 1 points ยท Posted at 20:27:57 on March 28, 2018 ยท (Permalink)

I'd buy this book.

fe__ ยท 1 points ยท Posted at 21:24:03 on March 28, 2018 ยท (Permalink)

Literally me irl

ricozhuthegreat ยท 1 points ยท Posted at 00:45:46 on March 29, 2018 ยท (Permalink)

What about the classic โ€œI will document it laterโ€?

dont_mess_with_tx ยท 1 points ยท Posted at 01:56:40 on March 29, 2018 ยท (Permalink)

Wait, that literally happened to me today (well yesterday actually cause it's almost 4AM now).

hemel7 ยท 1 points ยท Posted at 02:24:02 on March 29, 2018 ยท (Permalink)

Me: I will refactor that after I fix this bug. 1. Writes 100 lines of tests and 5 lines of actual code. 2. Tries to run the entire regression tests. 3. The 5 lines of code broke almost half of the tests. 4. Fixed it. 5. Run tests again. 6. DB error: "too many connections motherfucker" 7. Kill all db connections. 8. Try to run tests again. 9. DB is too busy. Breaks down. 10. Kill yourself.

Momochichi ยท 1 points ยท Posted at 03:53:17 on March 29, 2018 ยท (Permalink)

"Let's do Test-Driven development"

Eoussama ยท 1 points ยท Posted at 08:02:31 on March 29, 2018 ยท (Permalink)

Story of my life.

Lv_InSaNe_vL ยท 1 points ยท Posted at 01:26:39 on March 30, 2018 ยท (Permalink)

Ah I just fucking told myself this today