r/ProgrammerHumor • u/lRainZz • Mar 29 '23
But wait, there is more... which one are you REALLY? Advanced
1.8k
u/CreaZyp154 Mar 29 '23 edited Mar 29 '23
Codegolf style:
while(x==y){func1();func2();}
816
u/Sjeefr Mar 29 '23
Ultrawide monitors were specifically created for this style, right?
436
u/CreaZyp154 Mar 29 '23
This and being able to see the whole level in geometry dash
→ More replies144
43
→ More replies8
110
u/homo_ignotus Mar 29 '23
-3 bytes:
for(;x==y;func2())func1();
60
u/CynicalFucc Mar 29 '23
Golfing should be taught in school.. for a beginner, it breaks so many seemingly rigid templates and it forces a different way of thinking it's amazing.. golfing was probably the single best thing i did to improve in programming in the shortest amount of time. /* Not saying it leads to good practice and readable code ofc lol
→ More replies14
u/OneTurnMore Mar 29 '23 edited Mar 29 '23
EDIT: Got carried away with a golf
If x and y are numeric, we can shave off another:for(;x-y;func2())func1();
→ More replies21
u/homo_ignotus Mar 29 '23
No,
x-y
is equivalent tox!=y
. You have inverted the condition.→ More replies50
Mar 29 '23 edited Mar 30 '23
[deleted]
19
→ More replies7
u/loltheinternetz Mar 29 '23
Me too. If an if-then type of statement is short enough and simple as that, it’s one line. Very readable and reduces unnecessary line count.
→ More replies26
u/Makefile_dot_in Mar 29 '23
APL style: ```
define W(x, a...) while(x) {a;}
W(x==y,f1();f2()) ```
→ More replies
5.2k
u/Tobiwan03 Mar 29 '23
Kernighan & Ritchie. I always write like that.
1.4k
u/IJustAteABaguette Mar 29 '23
Kernighan & Ritchie. My auto format tool always works like that
311
u/genericneim Mar 29 '23
Definitely K&R, except when writing Kotlin. Then short lambdas are so tempting to leave as one-liners.
68
u/miraidensetsu Mar 29 '23
For me it's K&R, except when writing C#. Visual Studio enforces Allman.
48
u/Morthem Mar 29 '23 edited Mar 29 '23
And I fucking hate it for doing that.
Edit: Fucking ChatGPT told me how to fix it. Suffering is no more.
31
→ More replies4
→ More replies18
→ More replies24
u/Zombieattackr Mar 29 '23
Allan is the only other viable option, I was taught to write like that at first, but quickly dropped it for this.
6
u/b0w3n Mar 29 '23
I prefer K&R myself but Allman is 100% acceptable to me.
The rest feels like lunacy and I don't understand the argument for them at all.
→ More replies149
u/u0xee Mar 29 '23
If I remember correctly, K&R suggested 5 space indent. The 70's were a wild time
93
u/fakehalo Mar 29 '23
Damn, back when 80 columns was fancy... ......(tabs should have won, tab-gang unite)
→ More replies46
→ More replies7
u/melochupan Mar 29 '23
I hate when the first statement in a block has the same indent as the last expression in a multi-line
if
condition. So... 5 spaces prevents that, it's not that bad.→ More replies4
→ More replies271
u/jump-back-like-33 Mar 29 '23
Yeah wtf is wrong with everyone who doesn't do that? I've had about a dozen code style-guides mandated throughout my career and every single one was Kernighan & Ritchie.
I've never used C# professionally and that's the only language that seems to regularly diverge.
376
u/Tobiwan03 Mar 29 '23 edited Mar 29 '23
The only other good one is Allman. I understand, why people would use that. I personally just don't like the opening bracket having a full line.
163
u/R3D3-1 Mar 29 '23
Allman and K&R are the only styles I've ever actually seen. I am surprised by the "GNU" entry, since this implies a certain wide-spreadness.
Looking at some random source code file of Emacs, I find a mixture of Allman for toplevel definitions and "GNU" for control flow.
Personally I usually use K&R style, but that's just because it was the first style I learned through Java lectures and formatters, and I haven't worked on any Curly-braces projects with other prescribed code styles yet.
→ More replies59
u/wackywavingarmgumby Mar 29 '23
GNU has some weird formatting rules, like putting a function's return type on its own line.
37
u/JollyJoker3 Mar 29 '23
Worst I've seen is a Fortran compiler demanding eight spaces at the start of every line because those are reserved for punch card settings
→ More replies15
u/FesteringNeonDistrac Mar 29 '23
That's not really bad, just archaic.
10
u/JollyJoker3 Mar 29 '23
Archaic is using punch cards, bad is demanding space for punch card settings in a text file
→ More replies8
u/georgevalkov Mar 29 '23
That awkward moment your search for function definition returns no results, because someone thought it's a good idea to put the type on a separate line. 🤦🏼
→ More replies4
u/O_X_E_Y Mar 29 '23
I actually kinda like that but I cannot help but feel the braces guidelines are there to be quirky and different, there's pretty much no benefit to doing it this way
→ More replies35
u/bruhbruhthatsbruh Mar 29 '23
Our code base uses that style so I'm kinda forced to, but I got used to it. Not so bad compared to these other ones.
47
u/Zuruumi Mar 29 '23
The same for me. I prefer K&R style, but this one is reasonable. All the other styles are just objectively worse.
9
u/Niclamus Mar 29 '23
At my job our JavaScript for front end stuff uses K&R but the php backend uses Allman.
63
u/Aggravating_Moment78 Mar 29 '23
Allman is great for readability too
→ More replies23
u/terminal_prognosis Mar 29 '23
Which is surely the primary criterion.
8
u/Aggravating_Moment78 Mar 29 '23
For large codebases it is for sure, also if you need to read someone else’s code (which you do a lot better n a professional setting) it is a sure winner
31
u/georgevalkov Mar 29 '23
In the past I used K&R to save space. Then a friend enlightened me and now all my code uses Allman. The benefit is that it is easy to find where each block starts and ends. So the code is easier to read.
→ More replies4
u/mjkjr84 Mar 29 '23
That's why I always liked it but it has issues in code editors if you ever use the "folding" feature to collapse blocks because they expect K&R style so only fold up to the brace and leave that line showing. If you fold inside a nested block you have a dangling opening brace that messes with the readability of the folded code.
Now that I think about it though I have been using that feature less often so I think I'll be going back to Allman for my next project
→ More replies23
→ More replies11
u/_PM_ME_PANGOLINS_ Mar 29 '23
Allman is good if you've got complex signatures or conditions or bare scopes.
My Java ends up with some Allman when you've got some long type names and a couple of checked exceptions to declare.
101
u/Ascyt Mar 29 '23 edited Mar 29 '23
I use Allman since it's a lot easier for me to read. Looks a lot more like actual blocks imo.
16
u/Allian42 Mar 29 '23 edited Mar 29 '23
For me it's just easier to see the blocks. With K&R I need to count the blocks to see after which close I need to put a line and it end up being harder.
→ More replies→ More replies30
u/SjettepetJR Mar 29 '23
I always feel like Allman style makes the condition/loop/function definition feel more detached from the codeblock.
I don't really mind this for function and class definitions, but for loops and if statements it feels like they're not inherently linked to eachother.
26
u/Bladye Mar 29 '23
Yes, it's separated from main body and for me easier to read. k&r feels to cramped for backend with long and descriptive variable names.
→ More replies22
u/NoAttentionAtWrk Mar 29 '23
Allman style makes the condition/loop/function definition feel more detached from the codeblock
Yes that's the point since it's a different code block
5
u/Dustin_Echoes_UNSC Mar 29 '23
I think their comment is more about the opening bracket being on a new line as opposed to inline with the conditional (a la K&R). Yes, it's a different code block, but the conditional is what dictates when/if that block should run. It's different, but it is dependent.
IMO, since the brackets indicate the beginning and end of the conditional, they shouldn't be "detachable" from it in the formating. But maybe I'm just carrying over frustration from the ancient times, before your IDE could bitch at you for hitting "return" and creating a new block for the conditional and forgetting to delete the old one.
→ More replies25
u/tomtrein Mar 29 '23
To be fair enough, Allman does place 'else' at the same indentation as 'if', which K&R does not.
21
u/ZevTheDev Mar 29 '23 edited Mar 29 '23
if ( x==y ) { //Blah } else { //Blah blah }
Problem solved?
→ More replies7
u/tomtrein Mar 29 '23
You can use three `-symbols before and after your code to create a code block
→ More replies
1.2k
Mar 29 '23
I prefer to use whatever form the team chooses and the IDE editor provides.
Except Haskell. WTF?
371
u/GOKOP Mar 29 '23
Well "Haskell style" is meant to be used in Haskell, not in C-like languages. This image is dumb
128
Mar 29 '23
And rarely at that since you can skip the braces and semicolons in Haskell and rely just on indentation.
→ More replies31
u/GOKOP Mar 29 '23
This exact sort of thing that's in the post with separators at the beginning (in that case commas not semicolons) is used in data declarations
→ More replies→ More replies21
u/Andy_B_Goode Mar 29 '23
Yeah, imagine if someone made an image like this for spoken language grammar, only they used English words for all the examples. You'd end up with crap like:
German style: "The apple have I the boy already given"
→ More replies5
u/lelek-on-reddit Mar 29 '23
Den Apfel habe ich dem Jungen schon gegeben?
8
u/Andy_B_Goode Mar 29 '23
Yeah, that was just what Google Translate spat out, so I'm not even totally sure it's correct German grammar. I just wanted an example of a sentence with multiple nouns and the verb at the end.
→ More replies30
u/JackoKomm Mar 29 '23
There are languages where this makes sense. In this case it does not.
→ More replies9
46
u/wackywavingarmgumby Mar 29 '23
The only thing worse than Haskell style is pretending-to-be-python style: https://imgur.io/wG51k7v
28
u/XanXic Mar 29 '23 edited Mar 29 '23
Lmao, I was like "this is readable, what's wrong with it?" And for a half second wondering if you actually can do Fors without brackets somehow like if/else. THEN noticed the monstrosity down the side. Nightmarish
Sometimes I feel like I'd be lost without the little dotted lines connecting brackets VS22 does. That's next level
→ More replies→ More replies10
u/ArtOfWarfare Mar 29 '23
In Python you’d write the last three lines as
a[i], a[j] = a[j], a[i]
- no need to have a temporary variable.→ More replies46
919
u/General_Rate_8687 Mar 29 '23
I prefer Allman, but will use whatever the Team/Project uses.
150
u/Envenger Mar 29 '23
Even Haskell?
431
u/Nobodynever01 Mar 29 '23
Can't imagine any successful team using Haskell for long
→ More replies130
u/R3D3-1 Mar 29 '23
Using Haskell as a language, I can imagine.
Using Haskell style code formatting as displayed? Not so much.
→ More replies→ More replies23
24
u/dpash Mar 29 '23
And ideally the team or project uses a language style guide if they exist. I known Java and PHP both have opinionated style guides. Java code is better at following it.
→ More replies18
u/zilog88 Mar 29 '23
I'd say Allman is used by those who learned pascal first:)
→ More replies46
u/General_Rate_8687 Mar 29 '23
I never learned Pascal. I learned C, Java, Python and C++. Also PL/0, but that's not a real programming language (we wrote a Compiler for PL/0 at my University).
I use Allman because I find it best to read.
6
u/zilog88 Mar 29 '23
Ok, not directly supporting my statement but Pascal uses this kind of notation and is said to be one of the easiest languages to read.
→ More replies6
u/ogtfo Mar 29 '23
As long as it's some variation of Allman or K&R.
Everything else is awful.
→ More replies
521
u/Rebel_Johnny Mar 29 '23
Ritchie in js, Allman in c#
21
→ More replies233
u/Ascyt Mar 29 '23
Allman everywhere except for CSS, change my mind
22
→ More replies9
u/TheAntiSnipe Mar 29 '23
This for me but except JS. My instruction in JS was via Udemy and the instructor was very specific about K&R being best practice so I went with it. I guess I’d change if I had a job where one specific style was enforced, but at my workplace, we use Allman.
452
u/gdj11 Mar 29 '23
Anyone who does anything other than the first or second is a fucking psycho.
95
u/R3D3-1 Mar 29 '23
Apparently Emacs source code does indeed use "GNU" style. I guess I can see the value of that one, but I haven't ever used it myself...
→ More replies27
u/xouns Mar 29 '23
I can see the benefit of using GNU, however the 2space indentation makes me nervous and the problem it solves can be solved in other ways (doc-style comments at the beginning of each function for instance, or a new line after each function/ loop structure.
9
→ More replies22
u/Magpie1979 Mar 29 '23
Agreed, if any of my children use any of the others or marry anyone who does. I've failed as a parent.
→ More replies
144
u/GYN-k4H-Q3z-75B Mar 29 '23
Anything other than Allman or Kernighan & Ritchie is just disgusting.
→ More replies
36
u/Routine_Fuel8006 Mar 29 '23
Ratliff style
→ More replies10
153
u/Dalimyr Mar 29 '23
As a C# programmer, I use Allman at work because it's the norm in C#, but at home I prefer to use K&R.
19
u/sanjay_i Mar 29 '23
You change formatting options in your home IDE ?
→ More replies19
u/Dalimyr Mar 29 '23
Yep, one of the first things I do wherever I install VS or Rider.
4
4
u/ThrowAwayJoke1234 Mar 29 '23
first thing I do when I install jetbrains IDEs is to forget to install catppuccin for 3 months
→ More replies
70
u/Zdrobot Mar 29 '23
Allman,
but Horstmann also fascinates me.
→ More replies28
u/F54280 Mar 29 '23
I used to use Horstmann when vertical screen space was a concern, as it is as efficient as K&R. I also find it visually nice with local variables.
However, moving lines around is a pain, so Allman in general...
→ More replies4
u/Feathercrown Mar 29 '23
That's exactly why I think Horstmann is weird, on the first line you're mixing the flow control with the first line of the code block. Although I can see why you'd use it-- you can trace the brackets like Allman but it saves a line like K&R
21
u/Raxtuss1 Mar 29 '23
Whitesmith
→ More replies5
u/Gg101 Mar 29 '23 edited Mar 29 '23
Whitesmith is how I learned and what I prefer. I almost never see it anywhere though. But I have my own project so I'm going to do it my way.
Ratliff is also nice, usually just use it for CSS. Allman had always felt wrong.
18
u/LazarGrbovic Mar 29 '23
I didn't know it was called GNU, but that's the style I use all the time
12
→ More replies6
u/ThatDrunkenDwarf Mar 29 '23
Took me a while to find a GNU comment. I get really confused when reading if all my conditionals aren’t indented properly. If they are, I can just highlight that block and figure out what is in that particular conditional so much easier.
→ More replies
140
u/Stohastic- Mar 29 '23
Allman cause im not a freak, dc where, when or what it is for. Just the easiest to read, full stop
103
→ More replies14
u/visualdescript Mar 29 '23
Cut my teeth in Perl land and used Allman, now in JS land so obviously use K&R, but honestly prefer Allman, looks tidier as well imo. Obviously it's 1 line more verbose per block, but that is a small cost to pay.
57
u/nNanob Mar 29 '23
I love Haskell, but Haskell style shouldn't be used for any language that requires semicolons.
→ More replies16
u/EquinoxRex Mar 29 '23
I highly doubt anyone actually does it with semicolons like that, I've only ever seen it with commas for records or lists.
64
Mar 29 '23
there's another one
while (x == y){
func1();
func2();
}
72
u/R3D3-1 Mar 29 '23
Python style
while(true) { x+=1 ; if(x > y) { printf("You're done!n") ; break ;}}
→ More replies35
58
24
u/NervousHovercraft Mar 29 '23 edited Mar 29 '23
47
29
21
u/---RF--- Mar 29 '23
I'm an Alman, so Allman it is.
4
23
u/uberDoward Mar 29 '23
Allman has always been the easiest for me to read.
I read code 10x more than I write it.
Ergo, Allman wins, for me.
→ More replies
23
8
9
38
32
13
u/LifeHasLeft Mar 29 '23
K&R style, as they referred to it at my university. Kept an onion in my belt as it was the style at the time.
21
20
6
u/Zu_Landzonderhoop Mar 29 '23
For work Allman all the way but lisp looks beautiful and I'm gonna start using that in my private projects
→ More replies
4
5
u/Casique720 Mar 29 '23
I used to be Allman at the beginning of my coding career. Then I switched to Kernighan. It’s easier to see which brackets belong to which loop.
5
31
33
u/Specific-Assistant69 Mar 29 '23
Kernighan & Ritchie Find it the cleanest and clearest way. Used to be Allman but that is ways to much whitespace when maintaining applications.
→ More replies6
u/MrFlibble1138 Mar 29 '23
I started off with K&R in the 90s because of lack of screen real estate, but with modern displays I personally prefer the whitespace now for parsing.
19
11
8
7
u/FindingMyPrivates Mar 29 '23
I'm a Allman piece of shit. Java? I do. C++? I do. Python? I can't but I pretend I do. JavaScript? I dont do since I dislike it.
7
3
u/Spot_the_fox Mar 29 '23
If I knowingly use a style, then it's Ratliff. If I just write without thinking about it, it's sometimes K&R and sometimes Ratliff.
Also, I feel like this exact question has been asked many times in this sub.
4
u/greeny9000 Mar 29 '23
I think this Haskell example is a bit misleading. You don't use semicolons and curly brackets in that language much. This example could look like this in Haskell:
haskell
f x y = if x == y
then do
func1()
func2()
f x y
else $ return ()
Which looks fine imo (you could use guards to get rid of the if-else
as well). The brackets and semicolon aren't required and i never use them.
3
u/Shazvox Mar 29 '23
There's really only two choices here... Allman and WRONG!
4
u/CleverNameTheSecond Mar 29 '23
Incorrect. There are two choices here: Kernighan and Ritchie.
→ More replies
4
4
4
u/RadioMelon Mar 29 '23
Allman.
Sometimes Kernighan & Ritchie.
Usually whichever is easier to read in a given situation.
4
3
4
u/ItsSpaghettiLee2112 Mar 29 '23
Allman. It's the only one that makes sense as it's the most readable and most aesthetically pleasing.
14
7.8k
u/Calius1337 Mar 29 '23 •
[removed] — view removed comment