r/learnjavascript • • Oct 11 '20

JavaScript can keep you safe

Post image
1.0k Upvotes

87 comments sorted by

48

u/benabus Oct 11 '20

But... there's no exit condition. Is this the secret to immortality?

19

u/weoter Oct 11 '20

There's a seperate file where death waits ;)

2

u/Justindr0107 Nov 07 '20

I mean this really should be written as a Promise lol

1

u/AnonyMustardGas34 Mar 15 '21

Then the app terminates

11

u/markhole Oct 11 '20

There’s a good chance still_alive is global. It’s probably mutated in either of the 4 functions that are being called.

8

u/cyphern Oct 11 '20

Javascript functions can have side effects. Side effects like death.

2

u/xiipaoc Oct 11 '20

Those functions can throw exceptions.

2

u/Justindr0107 Nov 07 '20

I imagine it should be async await

0

u/[deleted] Oct 11 '20

[deleted]

6

u/knorfit Oct 11 '20

With JavaScript I feel that’s a safe bet. It’ll probably just fail silently in the background and toss you an undefined

105

u/warpedspockclone Oct 11 '20 edited Oct 11 '20

In my case, I use const. Y'all can use let.

Edit: to clear up any misunderstanding, here ya go https://youtu.be/AuBC2cwVnG4

44

u/queen-adreena Oct 11 '20

Using const is more optimistic about your chances of staying alive.

10

u/mark_b Oct 11 '20

Forever?

12

u/[deleted] Oct 11 '20

All I gotta do is hack into the Matrix and change my stillAlive variable from let to const

Immortality achieved

2

u/[deleted] Oct 11 '20

Regenerative medicine researchers around the world are making strides in learning, how we can reduce the impact of biological aging. So we may be looking at quite longer life spans than you may expect.

9

u/[deleted] Oct 11 '20

lmao as you get shot

Uncaught TypeError: invalid assignment to const 'still_alive'

1

u/HashFap Oct 11 '20

Just live and let live friend.

40

u/[deleted] Oct 11 '20

Now wearing one million masks and counting.

Also

snake_case & CapitalCase combined? Wtf

2

u/DrKrepz Oct 11 '20

I like using the former for variable declarations and the latter for functions/methods. Having said that, since I started using Vue a lot it's pretty much all CamelCase, mainly because it feels like the lines between the two have blurred a bit with computed data and props etc.

1

u/[deleted] Oct 11 '20

Vue and React classes are Capital Case but you don't invoke them like that

2

u/DrKrepz Oct 11 '20

Well it depends on how you're invoking them, in Vue at least. Still, in vanilla js there is still a good case for using different naming conventions for different contexts.

1

u/ThagAnderson helpful Oct 13 '20

Best practice states that classes and non-ES6 constructor functions should always begin with a capital letter. Nothing to do with Vue or React. The code in the picture would not pass any Javascript styling conventions.

18

u/ThagAnderson helpful Oct 11 '20

That won't pass any sane linting rulesets.

2

u/osoese Oct 11 '20

yeah this was already kind of pointed out on twitter that its not optimal js

1

u/MusicalDoofus Oct 12 '20

Thank you...

16

u/throwaway1253328 Oct 11 '20

- use of var

- snake case variable naming

- upper camel case method naming

- use of while loop

Yikes man

3

u/jasonbbg Oct 11 '20

the fact that u code reviewing an ads

7

u/throwaway1253328 Oct 11 '20

Those are just painful though. It's like if you saw someone playing a video game with an upside-down controller.

0

u/DrKrepz Oct 11 '20

var still had legitimate use cases. If you want a mutable variable that doesn't create a new block of scope, var is a perfectly good choice.

Also, using different naming conventions for variables Vs functions or methods can help to make code more readable.

As for while... I don't use it but interested to know why it might be problematic.

11

u/ricealexander Oct 11 '20

while is an appropriate loop for this use case, since you don't know how many times still_alive will continue to evaluate to true.

This while is smelly because we can't tell what triggers the exit condition. We can't reasonably infer, looking at this code, which function sets still_alive to false.

1

u/DrKrepz Oct 11 '20

Thanks, that makes sense.

2

u/ThagAnderson helpful Oct 13 '20

let does not "create a new block of scope", it is "block scoped", meaning it will not be available outside of its current block statement. var still works perfectly fine for historical reasons, but there is no instance where 'var' cannot be replaced by 'let' using proper programming techniques, and using 'var' is now considered bad practice.

Also, using different naming conventions for variables Vs functions or methods can help to make code more readable.

A scenario that defies all current best practice and style conventions for Javascript.

1

u/[deleted] Oct 11 '20

To your point on use of var, perhaps the author(s) of this billboard intended for still_alive to be globally scoped for access by other billboards in the area... XD

Ignore me, I have a terrible sense of humor.

12

u/nahuak Oct 11 '20

Inconsistent variable naming conventions.

8

u/RUGMJ7443 Oct 11 '20

This is amazing but what if people who don’t know JavaScript see this they will think there’s something wrong with it lol

8

u/kevinmrr Oct 11 '20

Which is like 97% of people, even there. This sign is just for a small handful of people.

I hate Silicon Valley.

3

u/gotta-lot Oct 11 '20

What languages are being used in Silicon Valley?

11

u/kevinmrr Oct 11 '20

English, Spanish, Mandarin, Ethiopian, Vietnamese are five of the most prevalent ones, I think.

2

u/gotta-lot Oct 11 '20

Am I being whooshed? The parent comment said if they didn't understand JavaScript, so I intended language to mean programming language.

1

u/DrKrepz Oct 11 '20

You have been whooshed.

2

u/sharmoooli Oct 11 '20

the most common one is bash, I bet.

3

u/Macaframa Oct 11 '20

You are seriously underestimating the programmer gentrification infestation going on in the Bay Area.

1

u/kevinmrr Nov 02 '20

You're right. 85%.

14

u/[deleted] Oct 11 '20

I may not be able to create fully fledged web apps yet in js, but I can understand this code and that’s more then I could do last year.

8

u/wesaboo Oct 11 '20

Dude thats what I keep telling myself! One of my initial goals was to understand programminghumor subreddit. Little goals are a great motivator 👍

1

u/[deleted] Oct 11 '20

Right there with you!

6

u/[deleted] Oct 11 '20

If still_alive ever evaluates to false I still recommend staying 6 ft apart.

5

u/[deleted] Oct 11 '20

Easy, those for which it evaluates to false are 6 feet under

5

u/zigzeira Oct 11 '20

ES5

2

u/Macaframa Oct 11 '20

What features in es6 would you use to make this different in any way?

4

u/james527 Oct 11 '20

const still_alive = true;

Make that one immutable.

2

u/Macaframa Oct 11 '20

Const is not immutable per se but go off.

1

u/james527 Oct 12 '20

True, it's just the reference that's immutable.

If we were referencing an array here, instead of a boolean, we'd still be able to change the contents of the array. We just wouldn't be able to reassign the still_alive variable to anything else.

5

u/BenZed Oct 11 '20

I do not like that billboards linting rules

4

u/metallaholic Oct 11 '20

var in 2020. It is the end of the world.

4

u/[deleted] Oct 11 '20

Y’all better fix that var right the heck now

3

u/doulos05 Oct 11 '20

The doctor told me I'm only allowed 1 test a day, so now I'm blocking one of the seats in the clinic for the next 23:59:59.999.

3

u/MobilePenor Oct 11 '20

so, one of these 4 things will change still_alive, eventually?

Nice side effects bro

3

u/SlaimeLannister Oct 11 '20

> Javascript can keep you safe

Statically typed languages would like to have a word with you

1

u/DrKrepz Oct 11 '20

Typescript?

3

u/[deleted] Oct 11 '20

I think this should have been written in C#

3

u/xiipaoc Oct 11 '20

I think it is C#.

2

u/burntrissoto Oct 11 '20

So what just clog the event loop for the rest of our lives?

2

u/Morphray Oct 11 '20
  • var instead of let?

  • mix of snake case and pascal case instead of camel case?

  • No way for mortality to end?

😡

2

u/himanshu03vsk Oct 11 '20

I would probably wreck my car whlie processing this code

3

u/MrSandyClams Oct 11 '20

just so you guys know, based on the syntax of the code, this sign could be written in C#, Java, Scala, maybe Kotlin if the author used semicolons liberally, and perhaps still other languages I don't know about, and still be legal and functional. So, not necessarily JS by any means

3

u/DettlafftheGreat Oct 11 '20

All karens be like:

ReferenceError: WearMask is not defined

3

u/[deleted] Oct 11 '20

This is silly. If any of the inner methods cause still_alive to become false they weren’t good ideas. If they never do then you just made an infinite loop. Also why is js code using snake case?

2

u/gabbywith_awhy Oct 11 '20

The Fact that they used var is making me cringe🥴 but I guess that was the point

1

u/trpt4him Oct 11 '20

Why no async?

0

u/danimalmidnight Oct 11 '20

await let stillAlive = true;

1

u/burger_chips Oct 11 '20

Lol😂😂😂

1

u/IBETITALL420 Oct 11 '20

WHO THE F still uses Var in 2020, but those are all very good methods below

3

u/IncyWincySpooder Oct 11 '20

Those of us who have to work in ES5 for a specific health organisation that still restricts some users to only using internet explorer and were still using windows xp until it was hacked a couple of years ago...

1

u/burntrissoto Oct 11 '20

i'm forced to, its unnecessary too seeing as we don't do work on legacy stuff. absolutely hate not being able to use es6.

1

u/[deleted] Oct 11 '20

This looks more like Swift to me

1

u/Jmarch0909 Oct 11 '20

Uncaught Reference Error: WashHands is not defined

1

u/Whereyoursisterwent Oct 11 '20

I understood that reference although I haven't learned about while yet

1

u/Mr_82 Oct 12 '20

Lol I like the subtlety in stating the first line, since if you're reading this you're alive, after all.

1

u/jayerp May 01 '23

I repeated that until I got too tired and ran out of energy.

1

u/Alexith Oct 12 '20

package main

import "fmt"

func main() { const stillAlive bool = false

if (!stillAlive) {
        fmt.Println("Six feet below")
   }

}

//Golang

0

u/densch92 Oct 11 '20

bullshit spreads even further! -.-

0

u/MusicalDoofus Oct 12 '20

To be clear if you code like this then fuck you

-4

u/_370HSSV_ Oct 11 '20

Brainwashed

-2

u/[deleted] Oct 11 '20

0

u/[deleted] Oct 11 '20

[deleted]

0

u/haikusbot Oct 11 '20

Shoulda been python. Could

Have just used a covid safe

Library and done!

- swiftrob


I detect haikus. And sometimes, successfully. Learn more about me.

Opt out of replies: "haikusbot opt out" | Delete my comment: "haikusbot delete"