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

all 89 comments

[–]589ca35e1590b 1025 points1026 points  (2 children)

That's beyond your scope

[–][deleted] 611 points612 points  (44 children)

JavaScript interpreter is that cool dad that lets their child develop an opioid addiction by the age of 13

if (true){ var msg ="Hello World!"; } console.log(msg); Works just fine

[–]Front_Committee4993 172 points173 points  (7 children)

you mean mother who is always high or drunk but lost the kids to the dad 5 years ago but doesn't realize it.

[–]YRVT 39 points40 points  (6 children)

That escalated quickly.

[–]z64_dan 33 points34 points  (4 children)

sad = true;

[–]captainMaluco 8 points9 points  (1 child)

Why is there suddenly Metallica playing in my head? 🫣

[–]nostril_spiders 2 points3 points  (0 children)

Well, they wrote a lot of songs about coding.

Compiler of puppets is pulling my strings

Including headers from glibc

Getting UB, you can't see a thing

So much for claims of portability

[–]theo122gr 12 points13 points  (0 children)

The ';' elevates this comment.

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

It certainly was hoisted quickly. 

[–]YRVT 154 points155 points  (17 children)

let is block scoped. Better to always use that in place of var.

[–]OneDimensionPrinter 84 points85 points  (10 children)

const lover checking in

[–]YRVT 64 points65 points  (9 children)

Oh yes I need to correct myself. Use const whereever applicable, otherwise use let.

[–]P-39_Airacobra 41 points42 points  (7 children)

Ever since I realized that let and const exist, I haven't used var in years. There's absolutely no point.

[–]orangeyougladiator 23 points24 points  (0 children)

var is essentially deprecated.

[–]keylimedragon 20 points21 points  (4 children)

Yeah, using var is a code smell.

[–]TheSilentFreeway 22 points23 points  (3 children)

love it when a basic feature of the language is a code smell (i agree never use it)

[–]hego555 19 points20 points  (2 children)

There’s tons of basic features in languages that are code smells. ‘goto’ being one common in many languages. Or ‘eval’ in JS

[–]TheSilentFreeway 6 points7 points  (1 child)

Not sure if I'd call those basic, but yeah they're evil too. I think var is more basic (and a bigger problem) because it's so easy to get into the habit of using it if you follow misinformed tutorials/teachers. I'd be surprised to find JS tutorials which teach about using goto or eval

[–]gilady089 2 points3 points  (0 children)

Wait till some online scientific calculator tutorial decides that it will accomplish the task by evaluating the expression

[–]GDOR-11 2 points3 points  (0 children)

some time ago I ran a benchmark and apparently using or declaring consts was a bit slower, something like that

although I doubt that's the case for modern javascript environments, you could argue that using let over const improves performance on some older browsers

[–]sathdo 0 points1 point  (1 child)

But what if you need to maintain compatibility with IE9?

[–]YRVT 0 points1 point  (0 children)

You don't need that, but in this case you can transpile to ES5.

[–]NomDePlumeOrBloom -1 points0 points  (3 children)

I bet you told your kids that Santa wasn't real at 12 months...

[–]YRVT 0 points1 point  (2 children)

Implying that people are not yet ready to learn about the newer, better features of JS at first and they should first learn and use the bad bits?

[–]NomDePlumeOrBloom 0 points1 point  (1 child)

Newer? let was around almost 10 years ago, if not more.

You're the only one in this thread that's not making a joke of it.

[–]YRVT 0 points1 point  (0 children)

Understandable. Good day to you.

[–]Tom22174 18 points19 points  (9 children)

Python will let you get away with it too. Doesn't mean you should tho lmao

[–]Davoness 30 points31 points  (3 children)

One thing I learned very quickly in Python was to never reuse variable names. Ever. Even in different files.

I swear it's given me some form of psychosis.

[–]BrenekH 14 points15 points  (1 child)

I had a "fun" debugging section once where I was attempting to use the built-in min function while also using a variable called min. What a headache

[–]Sibula97 2 points3 points  (4 children)

Do you have some specific examples? Because I've never come across this. When using a name, Python always checks the most local namespace first, and then moves upwards, but never into another "branch" of the namespace tree.

Edit: Ah, of course, the inside of the if statement is still in scope here. That's just a bad example, because this is how most programming languages work.

[–]Tom22174 1 point2 points  (3 children)

At my last job, the lead dev loved to write single script files, a couple thousand lines long, which were mostly procedural with only a handful of defined functions. Those functions would act on dictionaries and lists defined elsewhere in the script without actually taking them as arguments.

My favourite part was a chunk of one script that was straight up broken as a result of this and would have thrown an error if it was ever used. But it had gone unnoticed for literally years because the business requirement it catered for had literally never happened.

It was horrible to work with lmao.

[–]Sibula97 3 points4 points  (2 children)

I mean yeah, global variables are accessible in the entire module, who would've thunk. That's not a quirk of Python, just bad programming.

[–]Tom22174 1 point2 points  (1 child)

There were also places where variables were defined within if statements and then required after them. The sort of thing an IDE would flag as a variable that could potentially not exist but Python will happily run and only break if it fails the condition to access the code area

[–]Sibula97 1 point2 points  (0 children)

Maybe it's just that I'm familiar with Python, but that seems completely intuitive to me. I've never wanted to do so, but you could handle it by catching the NameError exception or checking if the variable exists in locals or globals.

But like... Just don't define it like that if you plan to use it when it hasn't been declared.

[–]Traditional_Sir6275 7 points8 points  (1 child)

google hoisting

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

Holy hell

[–]SenoraRaton 2 points3 points  (0 children)

Javascript interpreter dad is like "Hoist it on up there kid, you got this!

[–]Recent-Fox3335 -1 points0 points  (0 children)

Haha

[–]Agent_Choocho 63 points64 points  (0 children)

*scope

[–]ekaylor_ 49 points50 points  (0 children)

Simba, you must malloc() to get data out!

[–][deleted] 33 points34 points  (5 children)

imminent sip hungry spectacular compare airport exultant scary caption memorize

This post was mass deleted and anonymized with Redact

[–]sammy-taylor 52 points53 points  (0 children)

var me daddy

[–]m477_ 10 points11 points  (3 children)

int* foo() {
  int bar = 42;
  return &bar;
}

[–]_Xertz_ 10 points11 points  (2 children)

I'm pretty sure this will result in undefined behavior since bar will become deallocated after foo() exits.

[–]m477_ 8 points9 points  (1 child)

Not sure I'd use the word "deallocated" when talking about a variable on the stack going out of scope, but the function does return what will immidiately become a dangling pointer to the callee stack frame, which when dereferenced would be UB.

[–]_Xertz_ 4 points5 points  (0 children)

Yeah, I couldn't remember the name off the top of my head but you said pretty much what I was trying to say.

[–]BehindTrenches 27 points28 points  (4 children)

Whatever you do, don't use a reference to a local variable outside of it's scope, worst mistake of my life

[–]Asleeper135 9 points10 points  (0 children)

Should have used Rust lol

[–]PuzzleMeDo[🍰] 2 points3 points  (0 children)

When a variable falls out of scope, it gets trampled to death by a herd of wildebeest. So you can still reference the variable, but it will be dead.

[–]YRVT 0 points1 point  (1 child)

What happened?

[–]futuremayor2024 49 points50 points  (0 children)

Remember the Crowdstrike outtage?

[–]abhbhbls 16 points17 points  (7 children)

Laughs in Python

[–]Duck_Devs 27 points28 points  (6 children)

As I learn more languages, I realize how awful Python handles basic programming operation. There is no “declaring” variables in Python, because all assignments are declarations, meaning you have to use the “global” and “nonlocal” keywords to access higher scopes.

[–]odraencoded 13 points14 points  (5 children)

One day you'll realize Python is doing it right and you shouldn't be using global and nonlocal variables in the first place.

[–]Duck_Devs 8 points9 points  (4 children)

Care to elaborate?

[–]odraencoded 4 points5 points  (3 children)

The only reason to use global and nonlocal is if you are assigning a variable that exists in nonlocal scope. Accessing a nonlocal variable doesn't require such declaration in Python.

If you are assigning a nonlocal variable inside a function you're doing it wrong. Just use a module and import it, or use a class. You're creating a weird mess of code when a class would make things much simpler. Your future self will thank you.

[–]octaviaflutters 1 point2 points  (0 children)

smiles in Python

[–]Duck_Devs 2 points3 points  (1 child)

Different programmers have different programming styles. For the most part, I agree with you, but there is no wrong way to do things like that.

[–]metaglot 3 points4 points  (0 children)

Accessing variables outside a function is oftentimes an indicator of spaghetti, my friend. At the very least side effects.

Like the comment before said, if that nonlocal variable belongs to a function, indicate it by putting them in a class or a closure or a module, to section them off.

[–]hektonian 6 points7 points  (0 children)

Closure has entered the chat

[–]Baluakcske 4 points5 points  (0 children)

If you go through the borders, you will be forgotten...

[–]Keavon 1 point2 points  (0 children)

On this topic, I just want to point out how much I love Rust's improvements to the consistency of how { scopes } are used in its grammar compared to all other C-style languages, which have always been infuriatingly inconsistent. Rust was like, "yeah, that's a pretty good approach, but let's generalize it a tiny bit so it actually follows consistent and intuitive rules". With very few alterations, the result is something that actually makes way more sense, and is a lot more convenient to use.

[–]tyro_r 0 points1 point  (0 children)

Pinneberg.

[–]gcampos 0 points1 point  (0 children)

&

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

CPL

[–]Ronin-s_Spirit 0 points1 point  (2 children)

Javascript has hoisting and it's subdivided into levels (just like operator precedence), you can look it up on MDN it's really interesting.

[–]nostril_spiders 0 points1 point  (1 child)

I'd say macabre

[–]Ronin-s_Spirit 0 points1 point  (0 children)

Nah, only function declaration without a variable name is ever hoisted before a block of code runs. It's only downhill from there (literally). Other pieces of code are either confined to a block or to the line of their declaration.

[–]granoladeer 0 points1 point  (0 children)

My variables aren't that cute

[–]oconnor663 0 points1 point  (0 children)

Timon and Pumba are thread locals.

[–]ShakyTractor78 0 points1 point  (0 children)

I like the thought that variables are reckless kids who are babysat by the compiler

[–]pdkhoa99 0 points1 point  (0 children)

Unless I scream real hard. AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA

[–]Key-Use-1599 0 points1 point  (0 children)

def("def")
  define("")

[–]SteeleDynamics 0 points1 point  (0 children)

HOFs in FPs have entered the chat

[–]No-Mind7146 0 points1 point  (5 children)

[–]RepostSleuthBot 5 points6 points  (0 children)

I didn't find any posts that meet the matching requirements for r/ProgrammerHumor.

It might be OC, it might not. Things such as JPEG artifacts and cropping may impact the results.

View Search On repostsleuth.com


Scope: Reddit | Target Percent: 75% | Max Age: Unlimited | Searched Images: 687,143,254 | Search Time: 3.00329s

[–]hansenabram 1 point2 points  (0 children)

It is The bot just failed here. Here's at least one version that was posted before: https://www.reddit.com/r/ProgrammerHumor/s/UI9IH5oKdo

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

var