DEV Community

[Comment from a deleted post]
Collapse
 
ginsburgnm profile image
Noah Ginsburg

I don't know, I largely come from a python background and good God I hate JavaScript. It's such a fragile language.

Debugging it is a PITA too. I remember one project I worked on (I still hate what I did lol) there was a JS function I wrote that needed to run at load of page and at the end of every ajax call. The load of the page needed to do one extra thing. So I just put a flag in there to state on load right? Nah that didn't work, it'd never fire right on load.

So what ended up in production were two separate, nearly identical functions with a manifesto of a comment apologizing for how it is lol.

Collapse
 
jwp profile image
John Peters

Yes but it's function construct is a true first class citizen. Does python have that?

 
ginsburgnm profile image
Noah Ginsburg

I mean everything in python is a function. I'm not positive what you mean by JavaScript's function construct. But.

In python you can effectively make classes by just embedding function definitions.
You can generate functions programmatically by just modifying the global namespace (it's gross but you can do it, so use only when needed). You can get funky JavaScript like function definitions
Such as:

const sum = new Function('a', 'b', 'return a + b');

by using eval though you shouldn't, because that's gross even in JavaScript and evalis generally a bad idea.

 
jwp profile image
John Peters

Nice.

The concept of what Eval does has been around for 50 years or more. E.g. the mainframe language Rexx had an Eval statement. For me, I wouldn't ever say eval is a bad idea as ultimately it's a pseudo run time compiler transforming strings into executable statements. This ability in the right hands is really powerful.

There are rare problems where use of Eval like constructs are true lifesavers.