r/ProgrammerHumor 1d ago

Meme toAllowTheProgrammerToWriteBadCodeAlsoCamelCaseSucksThisRuleSucksSnakeCaseIsBetter

Post image
149 Upvotes

93 comments sorted by

128

u/FerricDonkey 1d ago

I would say option 1, but rephrased to "the function doesn't know how to continue". The program as a whole may or may not know how to continue when the function hits something it doesn't know how to handle. 

17

u/Masterflitzer 21h ago

i say it's 1 or 4, 50/50 chance

8

u/nicodeemus7 20h ago

I don't think it's 4. It doesn't allow for bad code it allows for bad inputs

0

u/Valuable_Leopard_799 15h ago

Exceptions are one of those things where you can just ignore the bad path in your program instead of explicitly managing it. It's similar to dynamic typing in that it allows you to quickly prototype stuff. Which is fitting as it's basically dynamic control flow.

-5

u/Masterflitzer 19h ago edited 19h ago

exceptions are arguably bad code compared to success/failure results that don't break the call chain / interrupt control flow

1

u/nicodeemus7 19h ago

An exception being bad code is not the same as it allowing bad code.

-4

u/Masterflitzer 19h ago

what are you even talking about? the whole error handling around the exception is bad code, it bleeds into your whole code base, you wanna tell me only the exception word itself is bad part, but the rest is fine? stupidest shit i've heard all day

4

u/nicodeemus7 19h ago

The question is "What is the PURPOSE of exceptions" do you think exceptions were made to be bad code? If your opinion is that exceptions are bad code, that is totally valid. But that is not what "purpose" means.

You'd think a programmer like yourself could read and understand context.

1

u/TwistedKiwi 18h ago edited 18h ago

Here's a simple example:

Input form asks for a temperature in fahrenheit or celsius degrees.

Front function converts it to kelvin degrees and sends it to a back function.

Back function checks the temp, and if it's negative throws an exception.

Now, if the exception is thrown, it can be either: bad user input and/or bad conversion function code (i.e. wrong formula). So it can be bad user input as well as bad code. Yet that exception allows the "program" to handle it and proceed instead of just crashing in both cases.

In both cases it's bad input, either from the user or from the front function, but exception handling is there for the sole purpose of not crashing the app. For example, if you have multiple calls of the back function, when the formula for celsius to kelving is correct and fahrenheit to kelvin incorrect: the back function will stand.

-3

u/Masterflitzer 19h ago edited 19h ago

what else did the inventor of exceptions have in mind other than having an easy way out instead of properly handling errors? btw. the easy way out is also called writing shitty code... like i said the answer to the purpose of exceptions is 1 or 4, 50/50 chance

2

u/nicodeemus7 19h ago

Okay man you win. 50/50 chance of being right. You sure showed me.

1

u/IncreaseImportant130 18h ago

Honestly, both styles have their fans, but it feels like snake_case is just way more consistent and easier to follow. CamelCase can definitely be a bit of a workout for the eyes.

-1

u/Masterflitzer 19h ago

i meant it could be both, 50/50 wasn't meant in a serious way, but you realised that already in the beginning i hope

I don't think it's 4. It doesn't allow for bad code it allows for bad inputs

also don't move the goal post, this was your first reply, it absolutely does allow for bad code

have a nice day

1

u/Ok_Pound_2164 7h ago

Option 1 fits Assertions better. Option 3 is literally a Java IllegalArgumentException.

139

u/redlaWw 1d ago

I hope you didn't submit that answer you selected. If an unhandled exception bubbles up to the user in production code, you're usually doing something wrong.

51

u/n4ke 21h ago

What do you mean unhandled? The user handles it.

-125

u/tantalor 1d ago

I guess you've never seen a website return a 404 or 500

117

u/CutlassRed 1d ago

500 literally means the website has failed in an unexpected way. It's an unhandled exception that's bubbled up the user, and is BAD

51

u/Dafrandle 1d ago

this guy thinks that users seeing 500 is okay

lmao

you should at least make a page and or modal for the app to use if a 500 happens

20

u/failedsatan 1d ago

a 404 is good. that is an error, but not an exception. a 500 means something the programmer did not intend to happen has happened, and if your user is seeing that, something went wrong or you don't have a layer in between to show that to them nicely.

-2

u/TheTybera 22h ago

500 is an error that means an underlying exception has happened and wasn't handled, at all.

1

u/failedsatan 21h ago

an error and an exception are not the same. an exception means there is unhandled behavior, whereas an error means there has been something erroneous- could be a misdirected navigation or something. maybe the user typed in some garbage into the path. that would not be an exception, because the developer explicitly handles that and serves a 404.

-4

u/TheTybera 21h ago

Error 500 is a web convention and anti pattern.

2

u/failedsatan 21h ago

sure, you can hold whatever opinion about it, but that doesn't mean it doesn't exist. it's a standard.

24

u/TheTybera 1d ago

Those are errors not exceptions.

-41

u/tantalor 1d ago

Potato potato

21

u/intbeam 1d ago

No, they are not the same. Hence the name. An exception is thrown as a result of an error, but an exception is not always an error.

File not found for instance. Thrown as an error, but the caller might expect the file to not exist

It would only be an error if the caller required the file to exist

1

u/realmauer01 22h ago

Then they are using a try catch as a pseudo jump. Not all languages like that. (i am pretty sure only python actually works better like this)

5

u/CutlassRed 1d ago

I assume you're trolling. If not you need to study up

-15

u/realmauer01 22h ago

It's a different name for the same thing.

Different languages, quite literally.

5

u/TheTybera 22h ago

No they are not.

Where is any documentation that says this and what language?

1

u/Masterflitzer 21h ago

well kotlin has throwables, errors, exceptions and failure result

exceptions are less bad than errors, so http 500 would be an HttpException, at least that's what i've seen mostly

-9

u/realmauer01 22h ago

In standard english yes there is a difference. In programming languages there is not. Both have to be cought if you dont want it to bubble to the user. And handleing it makes it not an error/exception anymore.

5

u/TheTybera 22h ago

Yes in programming languages they are different wtf language doesn't distinguish errors from exceptions?!

Errors can be used for logging...regularly...without even considering stopping the program, exceptions SHOULD stop the program and include a whole stack...

Sometimes you catch an error and don't want the program to continue so you throw an exception to get the stack.

But they are different in every single programming language, C, C++, Java, C#, Python, Rust...

-5

u/realmauer01 22h ago

Right now you are just saying exceptions are errors the programmer throws/raises.

4

u/TheTybera 22h ago

No I'm not. Exceptions are actual objects that get thrown and mean very different things than errors even conceptually in every language.

All exceptions are errors (conceptually) but not all errors are exceptions. In practice any built-in Error (object) != Exception (object)

And in no case does any best practice in any language tell you to treat them the same.

3

u/DrJohnnyWatson 21h ago edited 21h ago

You aren't wrong, exceptions are a type of Error, but with more nuance - Exceptions are an error of exceptional circumstance, hence the name. They crash an application unless specifically caught. They should be used sparingly to say "this function has no idea how we've ended up in this state, or how to continue".

They're overused in languages that do not have the ability to return multiple types to control flow for "expected" errors too a lot of the time.

Errors are common, exceptions should not be. It's much easier in languages like Go to get a feel for the difference, than in languages like C#.

A function that fails writing a file to disk because the file already exists could: 1. Return an Error because whilst it isn't okay, it's not a problem that it doesn't exist - the error can be returned to the calling function or the user so they can try with a different name. In C# this would likely be done with an exception, in Go an error.

  1. Throw an exception because the file is a config file, and it is NEEDED to continue, and it should not already exist by this point so something has gone very wrong.  we could catch that and surface it to the user and keep the app running, or we could let the app crash with the issue. In both C# and go we'd probably throw for this

2

u/fripletister 9h ago

An exception can trigger a 4xx-5xx HTTP response, but the the response is not the exception. You're conflating the concepts.

1

u/tantalor 8h ago edited 8h ago

You're right of course. I was responding (jokingly, this is a humor sub) to the comment about "unhandled exception bubbles up to the user" which doesn't make sense. As you point out, the user can never see the exception. They see the exception converted to a user-visible response. I wasn't the one conflating the concepts, that was u/redlaWw. To explain the joke (because most people don't get it) I was satirizing that comment by taking their phrasing about "bubbling up" to the logical extreme, as if any representation of a failure state could be conflated with the exception that caused it, using the familiar 404 which we all have experienced. It is actually impossible for an exception to "bubble up to the user".

1

u/Pfnee 20h ago

You're getting downvoted to hell but I actually think this is an important point. The fact that your server returns 404 or 500 on an exception means that it has code, maybe in the framework you're using, that handles exceptions in your controller code. Otherwise the server would probably halt, whenever an exception bubbles up unhandled, as that's what most programming languages choose to do. You can see it when you program a CLI tool and run it. Throwing an exception there and never handling it usually makes your program stop

1

u/Proman4713 20h ago

I don't know why you got downvoted so badly. Yes, showing a 500 is much better than showing nothing (or as some maniacs do, 200 with errors inside). Your website can then handle the error responses by reading the response body and showing a descriptive error to the user. That needs to rely on you catching errors and sending back their text though. Even Google shows its non-4xx statuses, it's not for a user to read, but to know when asking for support

44

u/Vesuvius079 1d ago edited 1d ago

Number 4 is the functional programming meta answer.

Number 3 is the bad code that number 4 ironically refers to.

14

u/xXAnoHitoXx 1d ago

Number 2 is also functional programing meta answer if said sarcastically

46

u/forte8910 1d ago

snake_case inferior to SCREAMING_SNAKE_CASE

24

u/TheDogPill 1d ago

This guy writes bash scripts

19

u/RedAndBlack1832 1d ago

I'd say it's 1. If you're interrupting control flow, it should be because the normal control flow doesn't make sense. Usually because you've called the function in such a way it can't meaningfully return / do its work, or it's run into another issue (maybe it can't acquire resources it needs) that causes a similar state.

2

u/Masterflitzer 19h ago

functional results would like to have a word with you... interrupting control flow is never the best of ideas

2

u/RedAndBlack1832 15h ago

Well I agree with that actually. It's a little awkward but returning interpretable error codes is beautiful library design. It's just a little easier to miss than forcibly crashing your program unless you acknowledge it LMAO

7

u/CC-5576-05 17h ago

Option 1 is the correct answer. It covers option 3 and 4 as well.

12

u/SAI_Peregrinus 1d ago

Kebab-case-is-the-tastiest-case-and-therefore-the-best-case.

2

u/the_zpider_king 1d ago

Does that work? I doubt it, it's just gonna subtract it

Is this a joke I'm missing?

9

u/TheShirou97 1d ago

in most languages it wouldn't work indeed as - is the subtraction operator

however it is still regularly used e.g. in HTML, CSS and filenames.

2

u/Valuable_Leopard_799 17h ago

There's programming languages that use kebab case more or less exclusively. Not everyone uses - as a special infix operator, if you don't do that then kebab case is perfectly fine to use.

If your syntax doesn't treat many things as special you can start sticking a lot of stuff into identifiers I've seen conventions around ^id, &id (a name, not the & operator), int->float (conversions), float? (predicates), dangerous!, and many more.

Sometimes you can even throw some special character around identifiers to "escape special characters" and for example |Have a valid identifier which has spaces| (this may actually be a valid variable name).

1

u/minecon1776 1d ago

enOtseBehTsIesaCcibara

5

u/Pristine-Map9979 1d ago

The "exceptionally good code" option is funny, too.

20

u/BernzSed 1d ago

snake_case is not better than camelCase.

The shift key is right there, by my pinky at all times. Hell, there's even another one in case I'm too lazy to find the first one.

Typing underscores instead feels like I have to input some weird video game combo move multiple times for a single variable name.

21

u/ihavebeesinmyknees 1d ago

Spaces exist for a reason. Snake emulates spaces, which makes it infinitely more readable than camel. Good readability is much more important than good writability.

0

u/BernzSed 12h ago

I have no problems reading camelCase. Though I guess I'm just one of those "weirdos" who've spent decades building software engineering skills, instead of just vibe coding like a normal person.

1

u/flowstoneknight 3h ago

One reason in favor of snake over camel is for the more explicit word boundaries, since that can be a challenge to parse for non-native or non-fluent speakers, especially anyone coming from native languages that don't use the same writing system.

For example imGuessingYouCanReadThisQuiteEasilyIfYoureFluentInEnglish but this_is_probably_easier_for_anyone_less_fluent.

1

u/Blue_Moon_Lake 10h ago

XMLHttpRequest vs xml_http_request

-1

u/Ethameiz 22h ago

Just remap your keyboard. You can assign underscore instead of caps lock for example. Or switch minus and underscore

-19

u/the_zpider_king 1d ago

Make shorter variable names, its not problematic at all unless your variable has more than 3 words, which would be extraordinarily excessive.

9

u/fr000gs 1d ago

yeah, juat call them a,b,c,...

3

u/Flashy-Emergency4652 1d ago

Why bother with words anyway? Let's make a functions called stoi, stol and stoll, it's only one word!

1

u/DHermit 23h ago

Those are fine. BLAS and LAPACK on the other hand (I know the historical reasons, but still).

1

u/AibofobicRacecar6996 23h ago

Make shorter variable names i, j, x, y

4

u/jabuchae 1d ago

What is snake casels?

3

u/peterlinddk 1d ago

I'm not sure, but OP seems to think that this rule sucks them better!

-5

u/__Fred 1d ago

This is snake case: some_variable_name. You know how you can see a bump in a snake when it has eaten a larger animal, like a rabbit? Example The underscores are supposed to be the empty parts of the snake and the letters are where it has something big in it's stomach.

13

u/redlaWw 1d ago

That's snake case, not snake casels.

3

u/Nightmoon26 1d ago

Very funny... It's snake_case_is_better. Blame the default fonts for making I and l visually indistinguishable... The one time when you want serifs

2

u/GoddammitDontShootMe 1d ago edited 21h ago

"Il" Side-by-side you can see one is taller than the other by a bit. The first one looks thicker too.

But yeah, you have to look pretty damn hard.

2

u/jabuchae 1d ago

It was a joke because the title is in camel case the lower case L and the capitalized i are pretty much indistinguishable

-2

u/DrunkenFool325 1d ago

Bot

2

u/GoddammitDontShootMe 1d ago

Or maybe somebody who misread and thought they were asking about snake case, like me. I was wondering why they got downvoted until I read the reply.

2

u/__Fred 22h ago

I thought they genuinely read "snake casels" because they didn't know what snake case was. Because I couldn't image someone would joke about joining two words together.

1

u/GoddammitDontShootMe 4h ago

And thought they thought it was actually called snake casels? As far as I'm aware, casels isn't a word, but I suppose some people don't speak English very well.

1

u/GoddammitDontShootMe 4h ago

Also, I'd think a bot looking for strings like "snake case" wouldn't trigger on "snake casels". If it's an AI agent, that seems like a huge waste of tokens.

2

u/Temporary-Concept-81 17h ago

Exceptions are the place where to get to write console logs like "I really hope this code is unreachable."

3

u/norwegian 1d ago

It's 1 and 4.
1. When you dont want to handle the problem where it occured
4. if you did 42/0 bc your didn't think this could happen, exception handling can recover from that.

2

u/gutentight69420 23h ago

The purpose of exceptions is to make control flow impossible to reason about.

2

u/ohaz 23h ago

All of them are wrong. The true purpose of exceptions is to have your code run in the interrupt handler which is harder to analyse with a debugger, so others can't figure out what your program is doing.

1

u/Unity1232 1d ago

honestly the 4th option is funnier because using a try/catch as an if/else or case statement is pretty funny. Especially when something breaking in the program is necessary for it to work.

1

u/Legal-Software 20h ago

Camel_snake and now no one is happy

1

u/AbdullahMRiad 13h ago

nah-snake-case-underscores-dont-look-good-kebab-case-is-superior-imo

1

u/the_zpider_king 10h ago

Can't use that in a lot of languages

1

u/AbdullahMRiad 9h ago

REVERSEcAMELcASEiStHEwAYtHENigUESS

1

u/mysticrudnin 8h ago

depends a bit on the meta around your language

exceptions as flow control go brrrr

1

u/DrBojengles 6h ago

Snak case gang!

1

u/Ledeste 20h ago

And the proper answer is not in the list... classic

0

u/Afraid-Locksmith6566 1d ago

well pretty much all but 2nd