[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
Why is writing "clever" code discouraged?
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /g/ - Technology

Thread replies: 25
Thread images: 4
File: 1443390905951.jpg (609 KB, 849x565) Image search: [Google]
1443390905951.jpg
609 KB, 849x565
Why is writing "clever" code discouraged?
>>
>>54324431
Readability > boilerplate hacks
>>
The length of the comment required to explain what the fuck is going on is inversely proportional to how clever the code is
>>
>>54324431
Your code is clever if it
>saves significant runtime
>fixes a bug
>makes clunky code readable

Your code is not clever if
>it doesn't do anything of the above but just reduces 3 readable lines into 1 unreadable line just because you're a special snowflake code artisan
>>
>>54324469
This
>>
>>54324431
Because I don't want to work with this
>>
File: 1418701745481.jpg (30 KB, 283x438) Image search: [Google]
1418701745481.jpg
30 KB, 283x438
>>54324505
>>
What is clever according to you?
>>
>>54324431
It isn't if your code is readable. There's a difference between writing understandable code that happens to be terse and terse code for the sake of terseness.
>>
>>54324431
Define clever. Is it clever to write the shortest code, to hide meaning from others like a riddle, to write one time workarounds for systemic design flaws?
>>
Because it's "clever".
>>
>>54324431
It's a maintanence burden and you are not a soloprogrammer. If you save 1/50th of runtime execution time it is not worth it to sacrifice the code clarity.
>>
>>54324431
Maintainability, and optimizing compilers.
>>
Because someone has to maintain your shit in the real world.

Be as clever as you want as a hobbyist.

Write "clever" code for production and you'll be told nicely to stop it.

Continue writing "clever" code and you'll be instructed not so nicely to stop it, or you'll be fired.

Resources are cheap, debugging and maintenance are not. Unless you're working with embedded systems, and even then it's got to some very, very basic shit with sub 256 MB memory; there is no reason to ever be clever.
>>
>>54324469

mostly this

if only you can read your code, you are doing wrong unless that anon said
>>
>>54328869
job security, anon
>>
>>54324565
unintuitive and unconventional problem solving
>>
>>54326618
>256 MB memory
That's a lot of memory for embedded systems anon.
Think 1MB
>>
Because I don't have time to figure out your clever spaghetti shit.
>>
all of the above applies to Normal Shit. but if you're writing something that needs to be fast as possible then use whatever hacky shit you want as long as it can't break easily and document what you did
>>
>>54330174
No.

A clever program doesn't require hacky looking code. No matter how unconventional your program operates, you can always write the code in a way that makes it understandable. I know too many shitty programmers who (even though they know that this is not how programming works) seem to believe that the performance of a code is strictly proportional to its length. Higher level languages should be used to make the code as understandable as possible for humans, that's why we don't use assembly for everything.
>>
Because most programmers are brainlets, and get triggered by anything clever.
>>
>>54330548
This.

I got in trouble with my boss for using map, filter, reduce in one block. Each function made perfect sense, was a typical aggregation-kind of query, and it was very clear what it did even if I step away from my point of view.

Any time I make a variable that references a function or object, all of a sudden, it's unreadable
>>
File: 1432259490310.jpg (68 KB, 700x700) Image search: [Google]
1432259490310.jpg
68 KB, 700x700
>>54330548
>>54330596
fk u im trying my best
>>
>>54330084
1MB is still a lot.
Thread replies: 25
Thread images: 4

banner
banner
[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y] [Home]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.