r/javascript • • Dec 16 '18

Coming from Python to JS NSFW

const print = console.log

I found my safe space.

607 Upvotes

156 comments sorted by

View all comments

94

u/mishugashu Dec 16 '18

If I came across that shit at work, I'd git blame in a heartbeat and tell you to never do that again.

But if you're doing it in personal projects, more power to you, I guess. Nothing really wrong with it code-wise.

193

u/[deleted] Dec 16 '18

That's why it's marked NSFW!

54

u/Uhh_derp Dec 16 '18

Lol now I get it

16

u/yoda_of_usernames Dec 17 '18

checks out username does

2

u/willtoshower Dec 17 '18

Can I get a checks out on username?

0

u/[deleted] Dec 17 '18

[deleted]

26

u/placidified Dec 17 '18

console.log(error) // eslint-disable-line no-console

cries in legacy code

3

u/Morphray Dec 17 '18

You forgot eslint-disable-line semi also

2

u/Anaphase Dec 17 '18

nah, that's in the base rules #fucksemicolons

5

u/Bonsoir_Elliott Dec 17 '18

Genuine question: why is it bad to have ‘console.log’ in the code? Is it bad to generate logs in a Node app?

5

u/FrancisStokes Dec 17 '18

Console logs do not have a level associated with them, so you have no way to run your app with only error logs, or with debugging information. That makes it easy to not only write bad logs, but to get to a situation where you can't remove a bunch of related but distributed logs without some effort. Basically, logging without levels and organisation leads to bad code hygiene.

6

u/13steinj Dec 17 '18

Aren't the 4 levels info, error, warn, (output to stderr), and log (output to stdout)?

→ More replies (3)

1

u/mishugashu Dec 17 '18

Exactly. It's a useless alias of a function that shouldn't be checked in in the first place.

→ More replies (1)

4

u/kchoudhury Dec 17 '18

He aliased a function and it is amply obvious what it does. What standard did he violate?

5

u/mrbojingle Dec 17 '18

none, some people are just anal.

4

u/vellian Dec 17 '18

He's adding complexity with almost zero benefit. You have to look at the definition to see exactly what it does. Don't change the code for something like that. Change yourself. If it were something more complicated from another language that's complex then that's great. Don't do it for trivial shit like this.

Someone else pointed out that not binding this may cause problems. So he possibly introduced bugs as well.

Yeah it's a joke, but no, you should never do this.

6

u/kchoudhury Dec 17 '18

"Change yourself"

I hate this attitude so much. Programming languages and compilers are there to work for us, not the other way around.

5

u/vellian Dec 17 '18

You're adapting for other people, not languages or compilers. If you're working on a team you have to take this attitude. If not, you're more free to do what you want.

0

u/spazz_monkey Dec 17 '18

There's a dude at my work who did this in production code.

self = this

16

u/_xiphiaz Dec 17 '18

This used to be super common when creating JavaScript libraries before modules and arrow functions; it was used to maintain a reference to the parent scope for use within a callback function

2

u/spazz_monkey Dec 17 '18

Fair enough, I assumed it was coz he loves python

1

u/alejalapeno Dec 17 '18

I prefer(ed) _this = this

→ More replies (1)
→ More replies (2)