
Reverse Engineering One Line of JavaScript - akras14
https://www.alexkras.com/reverse-engineering-one-line-of-javascript/
======
cyberferret
Nice. But it does highlight a trend in modern programming languages such as
Ruby etc. where these one line shorthand methods are used to such an extent
these days that new programmers to the project have to spend an inordinate
amount of time reverse engineering some of these shortcuts to make sense of
program flow and understand the program in their heads.

Take the simple, quick initialiser:

    
    
        foo ||= 1
    

Instead of the more verbose

    
    
        if foo.nil?
          foo = 1
        end
    

Undoubtedly, the first line is a much cooler version, but like skinny jeans
was once cool - getting in and out of them far outweighed the cool factor.

~~~
methyl
I can't agree, if you are a Ruby programmer you immediately know what's going
on in the first line and it's definitely more readable - you see it at a
glance instead of having to scan three lines.

~~~
onion2k
_if you are a Ruby programmer_

cyberferret explicitly said it's a good idea to avoid shorthand methods
because _new programmers_ don't understand them, and you're making the
argument that they're OK because experienced programmers will understand them.
The essence of your argument is that if you've used the language enough to
know what the or-equals statement means then you'll know what it means. I'm
not convinced that's a good reason.

~~~
joshumax
Cyberferrit said new programmers to _the project_ , not specifically new to
the language or programming itself.

Working on emulation software I commonly run across snippets such as `res =
!!iRegisterVal` which results in some C newbies scratching their heads as to
why a useless double negation would be there. But for more seasoned developers
its intent can pretty easily recognized...

~~~
CrystalLangUser
Why is !! useful? Asking as a ruby programmer.

~~~
drusepth
Because Ruby doesn't have a to_boolean method. !! is used to convert "truthy"
or "falsy" values [0] into true boolean true or false values.

For example,

    
    
        def user_signed_in?
          !!current_user
        end
    

This returns "true" or "false", instead of a (truthy) User object or a (falsy)
nil.

[0]
[https://gist.github.com/jfarmer/2647362](https://gist.github.com/jfarmer/2647362)

------
zspitzer
I'd forgotten that setInterval will evaluate a string

------
dynamoa
Isn't this called un-obfuscating rather than reverse engineering?

~~~
nimchimpsky
It's JavaScript we can call it whatever ... reverse transpilation.

I bet there are a myriad frameworks to do it aswell.

Deobsufucizer.js Reverse-sj.io

~~~
zaptheimpaler
[https://github.com/beautify-web/js-beautify](https://github.com/beautify-
web/js-beautify)

------
thinkMOAR
Neat, enjoyable read for the friday afternoon.

Q: Whats that math/graphing app you have screenshots of?

~~~
feiss
It's [https://www.desmos.com/calculator](https://www.desmos.com/calculator) ,
really neat online tool

~~~
thinkMOAR
ah great, thanks!

