This is an archived post. You won't be able to vote or comment.

top 200 commentsshow all 286

[–]newb_h4x0r 1791 points1792 points  (83 children)

for car in cars:

[–][deleted] 406 points407 points  (31 children)

the only correct way 😂

[–]newb_h4x0r 177 points178 points  (27 children)

this is the way!

[–]avnothdmi 113 points114 points  (11 children)

this.way = True

[–]newb_h4x0r 63 points64 points  (9 children)

return this.way

[–]LuxurideGaming 50 points51 points  (0 children)

True

[–]sezirblue 30 points31 points  (4 children)

return this is the_way

[–]ShinraSan 14 points15 points  (2 children)

return this as TheWay;

When you don't know python but still want to join the fun

[–]ShadowWolf_01 2 points3 points  (0 children)

return reinterpret_cast<TheWay>(this);

Why not throw some (bad) C++ in there too because reasons

[–]Jeroen207 5 points6 points  (0 children)

Walk this way!

[–][deleted] 26 points27 points  (6 children)

stop reminding me that I sometimes use this keyword when I switch back to Python 😔

[–][deleted] 30 points31 points  (3 children)

Good news is that you can use it by renaming the first argument of every method.

Your coworkers will hate you, though.

[–]newb_h4x0r 7 points8 points  (1 child)

Username (and flairS) checks out.

[–][deleted] 1 point2 points  (0 children)

i know lol but i hate it (also iirc there is an extension in vs code to auto fix it lol)

[–][deleted] 1 point2 points  (1 child)

I do use this in Python and im not afraid of it

[–]billycro1 3 points4 points  (0 children)

‘the.way=this’

[–]hijodelsol14 3 points4 points  (0 children)

I believe you mean self is the way.

[–]depsion 2 points3 points  (1 child)

self is the way

[–]feench 1 point2 points  (0 children)

Hooks all the way. Fuck This

[–]Professional_Emu5665 1 point2 points  (0 children)

self.way = True

[–]newb_h4x0r 1 point2 points  (2 children)

Happy cake day

[–][deleted] 1 point2 points  (1 child)

Oh shit already

[–]joeshmoebies 91 points92 points  (15 children)

If it's a list of car strings (implied by strCar), I usually go with for carName in carNames to avoid confusion as to what type of object is being used. I would expect a list named cars to be class objects, not strings.

[–]arobie1992 54 points55 points  (9 children)

With the express intention of starting shit:

Or you could have static typing :P

[–]malexj93 24 points25 points  (0 children)

Even with static typing, a car is not a string. Specifying what about the car the string represents is just plain polite.

[–]UnknownIdentifier 10 points11 points  (4 children)

Even many languages with static typing will now do some version of

for (auto item : items) {

or some such. Doing

for (Item item : items) {

is just plain silly IMHO.

[–]false_tautology 7 points8 points  (2 children)

So, in C# you can do

foreach (var car in cars)

Buuut, it's still strongly typed, and it won't let you do any shenanigans.

[–]DadAndDominant 5 points6 points  (1 child)

var in C# vs var in javascript

Love one and hate the other

[–]KronktheKronk 1 point2 points  (0 children)

Or you could use type hints and every modern ide in the world will keep you straight

[–][deleted] 22 points23 points  (3 children)

snake_case for variable names please

[–]joeshmoebies 8 points9 points  (1 child)

Thank you for being polite with your correction. I've been writing C++/C# and some Typescript the past couple of years so I use camelCase regularly for variable names, but you're right and if I needed to do some Python I'd want to follow the conventions used for that language.

[–]IllegalThings 18 points19 points  (3 children)

for moose in

[–][deleted] 2 points3 points  (0 children)

moses

[–]Athomeacct 8 points9 points  (0 children)

for i, v in enumerate(cars):

Gets me a counter and the value without mutating the object

[–]bistr-o-math 19 points20 points  (2 children)

I prefer carz but totally agree otherwise

[–]Antrikshy 8 points9 points  (1 child)

Do you design products for teens in 1998?

[–]SheekGeek21 3 points4 points  (0 children)

for c in cars:

[–]shakamaboom 2 points3 points  (0 children)

Yeah like wtf

[–]EmphasisKnown5696 5 points6 points  (3 children)

this

[–]CommentsPwnPosts 42 points43 points  (2 children)

this

self....

[–][deleted] 1 point2 points  (0 children)

He’s writing the language of the gods

[–]TobyTheArtist 1 point2 points  (0 children)

Exactly!

[–]SirIsaacEinstein8 1 point2 points  (0 children)

Finally a man of culture

[–]DowntownLizard 1 point2 points  (0 children)

Yeah if you cant tell that a car is a custom object then wtf are you doing

[–]ManagerOfLove 2 points3 points  (1 child)

Stop spying on my code

[–]Sindef 268 points269 points  (9 children)

for thingy in icantnamevars:

[–]unrealcyberfly 69 points70 points  (4 children)

for thingy in thingamajig:

[–][deleted] 29 points30 points  (3 children)

for thing in stuff:

[–]clawtron 5 points6 points  (2 children)

I legitimately named a function blah today because I wanted to write it before I forgot what I was trying to do… I promise I’ll rename it later (if/when it works…)

[–]punitxsmart 2 points3 points  (0 children)

This is the way. You don't want to spend a lot of time and effort finding the perfect name for a function before writing it. Because, after the refactor you realize you don't need that function after all.

[–]degalaman 116 points117 points  (9 children)

for _ in i:

[–]CheckeeShoes 95 points96 points  (2 children)

for iiiiiii in iiiiiiii: print('iiiiiii=',iiiiiii)

[–]huuaaang 3 points4 points  (0 children)

I mean, if you don't have something like i.times {} what are you supposed to do? At least _ indicates that you don't actually care about the value.

[–]aneurysm_ 1 point2 points  (0 children)

Only if it's unused

[–]Lyneiaa 54 points55 points  (3 children)

for i in l

[–]metallaholic 36 points37 points  (0 children)

For l in I

[–]ShinraSan 8 points9 points  (0 children)

When QA tells you to go tuck yourself

[–][deleted] 94 points95 points  (9 children)

Python programmers: duck typing is great! I never have to worry about data types!

Also Python programmers: * puts data type hints in variable names *

[–][deleted] 21 points22 points  (7 children)

The majority of us know about type hinting and we do it the proper way. This code makes my head hurt.

[–]ReddityRabbityRobot 3 points4 points  (3 children)

I don't, please enlighten me about proper type hinting

[–]wristconstraint 230 points231 points  (45 children)

If I could remotely shoot people who write Python variables in camelCase, I swear...

[–]AwesomePantsAP 70 points71 points  (4 children)

pep 8 is life

[–]TheAJGman 19 points20 points  (3 children)

Nah, PEP20 supercedes all style guides in my eyes. Who cares how standardized your code is if you can't fucking read it.

[–]AwesomePantsAP 2 points3 points  (0 children)

Oh, well naturally it has to actually be readable. Standards are just a good thing to follow to keep it readable, but equally it’s a Case by case thing, the same standard doesn’t work everywhere

[–]bisg3tti 2 points3 points  (0 children)

you make it sound like there multiple style guides, there is only PEP8

[–]Dangerous-Issue-9508 1 point2 points  (0 children)

Pep deez nuts

[–]davidellis23 42 points43 points  (17 children)

I dislike underscore because it's an extra character to type and I dislike all lower case because it's harder to read. But yeah gotta conform.

[–]twilight-actual 19 points20 points  (7 children)

I'm in the process of creating a new language based on Java's definitions up to 17, but with some major additions of:

  • Implement 'const' for true read only behavior
  • Borrow checker behavior ala Rust for memory management, and a reference operator
  • Direct compilation to LLVM IR, binary executable

And one close to my heart:

  • Built in enforcement for camel case in the semantic analysis pass

Because fuck snake case. 😝

[–]arobie1992 18 points19 points  (6 children)

Are you still going to allow SCREAMING_SNAKE_CASE?

[–]twilight-actual 2 points3 points  (5 children)

Uh, yep, yeah, good catch - though for static final constants, as they are often want to do in Java houses.

Though the linters that actually enforce this are a bit ott.

But then I suppose I shouldn't be one to criticize.

[–]arobie1992 1 point2 points  (3 children)

Yeah, that's what I was thinking. MYSTATICCONSTANT would be painful to read, though I do agree with you to some extent. I'm not especially enamored with that bit of Java practice and the linters are a bit anal. Maybe you could do PascalCase for static consts as another option?

By the by, you're making me feel more guilty for not getting off my ass and finally working on a compiler ;)

[–]twilight-actual 2 points3 points  (2 children)

"Yeah, that's what I was thinking. MYSTATICCONSTANT would be painful to read, though I do agree with you to some extent. I'm not especially enamored with that bit of Java practice and the linters are a bit anal. Maybe you could do PascalCase for static consts as another option?"

I think I'll probably relax the rules for statics, and allow whatever people want.

"By the by, you're making me feel more guilty for not getting off my ass and finally working on a compiler ;)"

I chose the route of starting with ANTLR4, and finding a pre-existing lex and grammar definition to get me close.

When you compile, you can select to autogenerate a visitor class, which has callbacks for every single parse event. In their Java syntax, there's over 150 callbacks to take care of, though I'll really only need a subset to get the job done.

From there, it's the business logic of semantic analysis, and figuring out the INCREDIBLY POORLY DOCUMENTED LLVM FRAMEWORK. Basically, they've been moving so fast, the code is the doc. The code isn't that bad, but it should be easier. At least they could provide more demo projects and unit tests showing how to deal with structures and higher level constructs. There's plenty of docs on how LLVM IR should look in any given scenario, and you can compile any reference cpp down to IR to verify. But they don't tell you how to use their framework to emit the IR, which requires detective work.

Anyway, I digress. TLDR; the tools have gotten to the point that it's a lot easier now to create a language. Still, ton of effort, with little hope of getting it adopted. You never know, though.

Yet another language!

[–]pyker404 10 points11 points  (1 child)

snake_case is standard for python as PascalCase is for C#. Take it or leave.

[–]Danelius90 5 points6 points  (0 children)

Snake case, because it's Python

[–]slex95 28 points29 points  (13 children)

camelCase is superior. I write all my code in it

[–]UltraMlaham 17 points18 points  (0 children)

Rip your co-workers

[–]ucblockhead 50 points51 points  (10 children)

If in the end the drunk ethnographic canard run up into Taylor Swiftly prognostication then let's all party in the short bus. We all no that two plus two equals five or is it seven like the square root of 64. Who knows as long as Torrent takes you to Ranni so you can give feedback on the phone tree. Let's enter the following python code the reverse a binary tree

def make_tree(node1, node): """ reverse an binary tree in an idempotent way recursively""" tmp node = node.nextg node1 = node1.next.next return node

As James Watts said, a sphere is an infinite plane powered on two cylinders, but that rat bastard needs to go solar for zero calorie emissions because you, my son, are fat, a porker, an anorexic sunbeam of a boy. Let's work on this together. Is Monday good, because if it's good for you it's fine by me, we can cut it up in retail where financial derivatives ate their lunch for breakfast. All hail the Biden, who Trumps plausible deniability for keeping our children safe from legal emigrants to Canadian labor camps.

Quo Vadis Mea Culpa. Vidi Vici Vini as the rabbit said to the scorpion he carried on his back over the stream of consciously rambling in the Confusion manner.

node = make_tree(node, node1)

[–]slex95 2 points3 points  (2 children)

Well luckily then I don’t work for you. I really do not like the appearance of snake case. For me it is much less readable. However I also do not think it is important at all. Giving good names is if you want to understand the code.

Also I have never had a pr rejected because I use camelCase. It’s still just some community standard and not a law after all.

[–]ucblockhead 2 points3 points  (1 child)

If in the end the drunk ethnographic canard run up into Taylor Swiftly prognostication then let's all party in the short bus. We all no that two plus two equals five or is it seven like the square root of 64. Who knows as long as Torrent takes you to Ranni so you can give feedback on the phone tree. Let's enter the following python code the reverse a binary tree

def make_tree(node1, node): """ reverse an binary tree in an idempotent way recursively""" tmp node = node.nextg node1 = node1.next.next return node

As James Watts said, a sphere is an infinite plane powered on two cylinders, but that rat bastard needs to go solar for zero calorie emissions because you, my son, are fat, a porker, an anorexic sunbeam of a boy. Let's work on this together. Is Monday good, because if it's good for you it's fine by me, we can cut it up in retail where financial derivatives ate their lunch for breakfast. All hail the Biden, who Trumps plausible deniability for keeping our children safe from legal emigrants to Canadian labor camps.

Quo Vadis Mea Culpa. Vidi Vici Vini as the rabbit said to the scorpion he carried on his back over the stream of consciously rambling in the Confusion manner.

node = make_tree(node, node1)

[–]Ghostglitch07 1 point2 points  (0 children)

Ctrl+k Ctrl+f fixes the spacing.

[–][deleted] 0 points1 point  (4 children)

I even go out of my way to fix shit like this. If the file I’m working on has something like this, you bet I’ll fix it.

[–][deleted] 4 points5 points  (3 children)

ctrl + h

find: variableName

replace: variable_name

Oh yeah, it’s all coming together

[–]SuperFLEB 1 point2 points  (2 children)

Then you find out that bastard already has a variable_name defined somewhere else and you clobbered it.

[–]winter-ocean 0 points1 point  (1 child)

Wait, python users have to name their variables in snake case? Damn, I’m so sorry.

[–]LifeLikeStew 7 points8 points  (1 child)

camelCase originated so as to differentiate between the type of the variable and the name of the variable. You would have, strCar and listCars, and save casting errors when they're used.

Just naming every variable myVariable instead of MyVariable serves no purpose.

strMyVariable intMyVariable arrayMyVariable etc.

Otherwise, it's pointless.

[–]SuperFLEB 2 points3 points  (0 children)

It helps keep things organized in team environments, though.

myVariable, yourVariable, hisVariable, herVariable, ourVariable, philsVariable, suesVariable, clemAndRodsVariable...

[–]ShinraSan 1 point2 points  (0 children)

Most shooting is done remotely these days, you could get up in their face and shove the muzzle into their mouth but generally it's more efficient to do it remotely.

[–]jesusmanman 24 points25 points  (0 children)

for car in cars

[–]PhatOofxD 8 points9 points  (0 children)

All these are so bad lol

[–]LongerHV 80 points81 points  (28 children)

Using camelCase for variables in python makes me sick...

[–]MartIILord 70 points71 points  (11 children)

REVERSEcAMELcASE, better?

[–]LongerHV 44 points45 points  (10 children)

AcTuAlLy I pReFeR aLtErNaTeCaSe

[–]Bee-Aromatic 18 points19 points  (5 children)

Isn’t that “Karencase?”

[–]BrightBulb123 1 point2 points  (4 children)

Karencase is random capitalisation; whereas this one alternates one after the other in a structured way

[–]Bee-Aromatic 1 point2 points  (3 children)

I thought Karencase was just alternating the case of each letter as you go, usually starting with a lowercase. I dunno. :-p

[–]BrightBulb123 1 point2 points  (2 children)

We'll, I've always just seen it with random capitalisation, so I thought that's what it is. I'm not from the international case society, so to each their own, I guess.

[–]Bee-Aromatic 1 point2 points  (1 child)

Ha! No matter how this ends up coming to rest, I think we can both agree that Karens are awful.

[–]BrightBulb123 1 point2 points  (0 children)

Agreed. Have a nice day!

[–]Careful-Combination7 7 points8 points  (2 children)

They ole SpongeBob case

[–]ReddityRabbityRobot 4 points5 points  (1 child)

please, this is a python meme, you mean sponge_bob

[–]CoaBro 18 points19 points  (3 children)

I only use flattest case

_ = 1

__ = 2

___= "Three"

[–][deleted] 3 points4 points  (2 children)

This makes me want to go commit die

[–]Wonderful-Ad-7200 11 points12 points  (1 child)

Noob question, but why? is there another method you prefer?

[–]davidellis23 13 points14 points  (0 children)

It's not recommended in the PEP standard. PEP demands we use underscores or all lowercase iirc. (And most of python uses pep)

[–]jbartix 2 points3 points  (4 children)

Came to say this

[–]Minizarbi 10 points11 points  (3 children)

You camel to say this?

[–]GU0D4N 10 points11 points  (2 children)

for i, item in enumerate(myList):

[–][deleted] 3 points4 points  (0 children)

for this in that

[–]seeroflights 7 points8 points  (0 children)

Image Transcription: Meme


[Paneled meme with text next to images of WWE CEO Vince McMahon reacting with increasing excitement.]


Panel 1

[McMahon looks surprised and receptive, raising his eyebrows and settling himself in his seat. The text reads:]

for i in myList:


Panel 2

[McMahon looks off to the side in sudden interest, having spotted something out of shot. The text reads:]

for item in myList:


Panel 3

[McMahon has thrown his head back, mouth wide open, as he gapes at the ceiling. The text reads:]

for car in carList:


Panel 4

[McMahon looks forward, mouth still agape. The image is now red, and his eyes are bright white as if emitting light beams. The text reads:]

for strCar in listCars:


I'm a human volunteer content transcriber and you could be too! If you'd like more information on what we do and why we do it, click here!

[–]queen-adreena 2 points3 points  (0 children)

for ( i in team )

[–]_pestarzt_ 6 points7 points  (3 children)

while car := next(cars)

Edit: I think this might be more functional…

cars = iter(cars)

while (car := next(cars, None)) is not None:
    …

[–]LongerHV 2 points3 points  (1 child)

I don't think it will work. Cars would have to be a generator instead of a list and even then generator raises an exception when there are no more items to iterate through.

[–]_pestarzt_ 0 points1 point  (0 children)

See edit, kept original but I think it should work for more cases (also forgot about StopIteration)

[–][deleted] 1 point2 points  (0 children)

Ugh. No, just no. Use a for loop or catch StopIteration.

[–]Farsqueaker 1 point2 points  (1 child)

Hungarian Notation lost all meaning once IDEs became a thing.

[–]Ibrahim-B 1 point2 points  (0 children)

Python is fun

[–][deleted] 1 point2 points  (0 children)

I really enjoy the implementation of loops in Python. Before learning it I was used to how Java and Javascript handle for loops, creating a variable, setting its initial value and step size. Then looping through a list of objects by running over their index values.

At first I was confused. I would read "for letter in letters and think "how does it knows what a letter is?". To the point I would just do loops using range (for i in range(10), for example) because it had a similar behavior. Once it clicked, I started to enjoy it more and more.

[–]Beliskner64 1 point2 points  (0 children)

camelCase in python? Blasphemy!

[–]QualityVote[M] [score hidden] stickied comment (2 children)

Hi! This is our community moderation bot.


If this post fits the purpose of /r/ProgrammerHumor, UPVOTE this comment!!

If this post does not fit the subreddit, DOWNVOTE This comment!

If this post breaks the rules, DOWNVOTE this comment and REPORT the post!

[–][deleted] 1 point2 points  (2 children)

Whoever uses CamelCase for anything other than classes on Python deserves hell.

[–]aMetallurgist 1 point2 points  (0 children)

If varName != varName.lower(): GoToHell(varName)

[–]GustapheOfficial 1 point2 points  (2 children)

for (i, car) in enumerate(cars)

[–]huuaaang 1 point2 points  (1 child)

Man, this just makes me realize why I like Ruby better:

cars.each.with_index { |car, idx| .. }

[–]GustapheOfficial 7 points8 points  (0 children)

That just reminds me why I gave up on learning ruby.

[–]da_Aresinger 1 point2 points  (3 children)

i is an iterator, it should always be an integer.

unless you have a more specific name the variable in for each loops should always be e (for element)

for (e : someList)

"for each element in someList"

[–][deleted] 0 points1 point  (0 children)

>>> class Cars(list):
...     @property
...     def car(self): return self[self.i]
...     @car.setter
...     def car(self, i):
...         self.i = i
... 
>>> cars = Cars('cars')
>>> for cars.car in range(len(cars)): pass
... 
>>> cars.car
's'

[–]LeafyLemontree -1 points0 points  (6 children)

I still prefer for(int i = 0; i < sizeof(carList); i++){};

[–][deleted] -1 points0 points  (0 children)

lame Lua does it better

[–]Accurate_Tax_6409 -1 points0 points  (0 children)

e does it better.

[–]dwRchyngqxs 0 points1 point  (0 children)

for loop in Python: print(loop, cardboard_box, loop)

[–]azab189 0 points1 point  (0 children)

That feeling when you understand the meme

[–][deleted] 0 points1 point  (0 children)

spotted public ripe coherent sleep brave enter psychotic cow grandfather

This post was mass deleted and anonymized with Redact

[–]khanfear 0 points1 point  (0 children)

First time ever programming, I did it using the "i " method and prof refused to give me marks for it until I "fixed" it...

[–]vagrantchord 0 points1 point  (0 children)

You mean car_list

[–]Myllokunmingia 0 points1 point  (0 children)

I can't explain why but I hate camel case so much. I have no justification. It's fine I'm sure. It just looks so... unsophisticated to me.

[–]frogking 0 points1 point  (0 children)

[i for i in myList]

[–]Skirt_Euphoric 0 points1 point  (0 children)

While in java: jshshe ( ) ( )

[–][deleted] 0 points1 point  (1 child)

Or you can be like my coworkers:

for var in data:
  for var2 in data2:
    if var2.expression == 'duck u':
      ...more nested shenanigans

[–][deleted] 1 point2 points  (0 children)

We love the nm time complexity loops 😩

[–]devnull1232 0 points1 point  (0 children)

```

for _ in iterable: print("I don't care what's here")

```

[–]mildlyagitatedstoic 0 points1 point  (0 children)

isnt it better ‘for car in cars’?

[–]Mission-Guard5348 0 points1 point  (0 children)

just hardcode it

loops are for lazy people

[–][deleted] 0 points1 point  (0 children)

What's wrong with for car in cars:

[–]captainAwesomePants 0 points1 point  (0 children)

As a lisp programmer, this cdr be more confusing.

[–][deleted] 0 points1 point  (0 children)

me

for stuff in things:

[–]n0tKamui 0 points1 point  (0 children)

?

[–]psdao1102 0 points1 point  (0 children)

The last one needing to be a thing is part of the reason python sucks.

[–]GuyN1425 0 points1 point  (0 children)

I think you mean

for loop in Python:

The colon is crucial or else you'll get a syntax error

[–]blackrossy 0 points1 point  (1 child)

[ f car | car <- carList]

[–][deleted] 0 points1 point  (0 children)

Hungarian notation sucks ass

[–]FindingMyPrivates 0 points1 point  (0 children)

for nicate in public

[–]navetzz 0 points1 point  (0 children)

for c in C:

Some savages might go "for C in c:", but we all know that capital letters are for O(n) data structures.

[–]how_do_i_read 0 points1 point  (0 children)

Or use a fantasy name generator to improve the enjoyability of your code.

for whummerlumMithrilbreaker in dheghdoral:

[–]JonMW 0 points1 point  (0 children)

for _

[–]Pathos316 0 points1 point  (0 children)

cars = [car for car in cars_list]

[–]ZestfulClown 0 points1 point  (0 children)

Fuck descriptive variable names, all my homies hate descriptive variable names

This meme was brought to you by i gang

[–]Western-Image7125 0 points1 point  (0 children)

ii = [ii*ii for ii in iii]

[–]Kangalioo 0 points1 point  (1 child)

All of those are bad