Eval()?
-
Good, just in time so everyone has moved to Node.
-
There's still an awful lot of the web powered by PHP...
-
willing to pay for is bullet proof
My clients get "nuke proof" for free, 'cos really don't want to have to "do it again" :)
-
everyone has moved to Node
No, just the dedicated followers of the hype train. PHP fell off the back of that quite a long time ago, but then lots of things do. There's plenty of room back here though, doing useful stuff for real people without too much fuss.
-
Have you seen The Thread yet? In the lounge,
I haven't been able to see the Lounge since about May, and I have no idea why. Stupid Dicsource.
-
You've dropped down to Trust Level 2 because you haven't jumped through enough hoops lately. You can see exactly which hoops you need to jump through to achieve Trust Level 3 again by asking shadowmod.
-
Feh... I need to view more topics?!
-
There's still a lot of awful web sites powered by PHP...
FTFYThen again, there's a lof of awful web sites, period, so that in and of itself is hardly PHP's fault. It has enough faults of its own already anyway, as do all of it's competitors...
-
There's the ones I build for work, they're fairly terrible, then there's the ones built in WordPress, they're all terrible. How do we feel about Wikipedia?
-
Don't ask me, all we'll be able to tell you is that your page performance is terrible and your users are being bombarded with error messages. Might even be able to include where the problem is coming from.
-
No, no, do we feel Wikipedia is terrible or not?
-
Which aspect? The aspiration? The content? The software? The editing culture?<there is a strict order here I think>
-
Which aspect?
Maybe the idea as such? Only highly-paid consultants should be allowed to distribute information of any kind.
-
Only highly-paid consultants should be allowed to distribute information of any kind.
“Consultants” and “information” in the same sentence…
-
“Consultants” and “information” in the same sentence…
Well, "information" in the business sense, obviously. Not in the Shannonian sense.
-
-
-
```javascript
// Any remaining arguments are passed as arguments to the constructor by
// conversion into a JSON array and trimming off the outer[
and]
args = JSON.stringify(
Array.prototype.splice.call(arguments, 1) ).slice(1, -1);/jslint evil: true/
result = eval('new Class(' + args + ')');
/jslint evil: false/I'm pretty sure that is no different than writing, ```javascript args = Array.prototype.slice.call(arguments, 1); // create an objConstructor whose constructor invokes the _Class_ constructor with args var objConstructor = function () { return _Class_.apply(this, args) || this; }; // set its prototype the same as _Class_ so objects will be instanceof _Class_ objConstructor.prototype = _Class_.prototype; // create the new object result = new objConstructor;
To return to the original topic,
eval()
comes in handy sometimes in code golf, but I can't think of many legitimate reasons to use it.
-
To return to the original topic, eval() comes in handy sometimes in code golf, but I can't think of many legitimate reasons to use it otherwise.
i have a hard time thinking that code golf is a legitimate use.
it's more of a toy use to me
-
Edited to remove "otherwise". Happy?
-
I think you're onto something there. I can't see any difference between a directly
new
ed object, theeval
factory or your solution. I'd share test code but that would involve logging into TDWTF from my work PC on my third day in a new job.
-
Happy?
only if you agree with me on the matter. ;-)
ithrewise put that back the way it was!
-
Yeah... I'd originally tried using
result = Object.create(_Class_)
before applying the_Class_
constructor to it, but then the object didn't yieldresult instanceof _Class_ == true
as it would for an object created directly withnew _Class_
.It'd be an interesting puzzle to put on CodeWars, if there's nothing similar already... I might have a look at some point.
-
but I can't think of many legitimate reasons to use it.
Here's a legitimate reason to use it: https://github.com/discourse/discourse/blob/master/lib/source_url.rb (enabled in development only. Splits the source files in the inspector by what they're actually called on disk.)
-
i can't help but feel that there has to be a better way of doing that...
-
TIL that my way of function argument usage was Doing It Wrong™ all the time.
locals
andblock
aren't used explicitly anywhere in the function body. So they're either dummy arguments, or using function arguments implicitly in a convoluted way is Doing It Right™.
-
So they're either dummy arguments,
probably this.
i prefer specifying dummy but required parameters named via underscores to indicate that they are intentionally dummy parameters
so the function would become:
def evaluate(scope, _, &__)
Unless of course Ruby does some stupid thing like "parameters must be named the same on the calling and receiving side of the function call"
-
Unless of course Ruby does some stupid thing like "parameters must be named the same on the calling and receiving side of the function call"
The Evil Ideas Thread is
Ruby seems to behave at least here (https://en.wikipedia.org/wiki/Ruby_%28programming_language%29#Differences_from_other_languages).
I prefer to name dummy arguments with explicit "dummy" in their names because there is no underscore or similar rule where I work.
-
I prefer to name dummy arguments with explicit "dummy" in their names because there is no underscore or similar rule where I work.
That also works. I use the underscore because the default setup in my IDE of choice these days raises warnings on unused parameters unless the parameter contains only underscores in its name, and further issues a warning when using a variable that contains only underscores in its name.
I could change that i guess, but this setup works and does stop me from accidentally using a dummy parameter without updating the name to something meaningful.
-
i can't help but feel that there has to be a better way of doing that...
Here's a worse way of doing it: Have one
<script>
tag for every single file. The development webserver is a bit slow at serving files, due to all the logging and stuff, so that's how you get 30-second page load times.
-
Here's a worse way of doing it: Have one <script> tag for every single file.
that is a worse way of doing it.
i didn't say there wasn't a worse way. just that i can't help but think there's a better.
also
that's how you get 30-second page load times.
you mean like we have here in production?
-
The development webserver is a bit slow at serving files
That happens sometimes…30-second page load times
…
What's it doing? Giving the files' shoes a polish before sending them out?
-
so that's how you get 30-second page load times.
30 seconds? Only? I remember when we cranked the timeout of one of our background web clients up to 240 seconds (4 minutes) because the page of our favorite web service provider needs up to 3 minutes to load. And then a 3rd party JavaScript kicks in and loads additional data at the mind-blowing speed of 50 Bytes per second. And it throws exceptions when some value isn't set (we don't know which one, only definiively not one we can influece in any way). And it is not even Discourse.
-
the mind-blowing speed of 50 Bytes per second
A little less than half the bandwidth of a 1970s-era V.22 modem. Well done.
-
A little less than half the bandwidth of a 1970s-era V.22 modem. Well done.
Also probably, but not certainly, slightly more than the bandwidth of a Navajo code talker reciting binary.
-
Interesting you should say that... I've always held that reincarnation must be true, because we couldn't possibly get off the hook that easy.
-
Took a while to infinfind the post you were replying to (would be nice if there was a link for this), but:
Who is to deny that reincarnation does happen, and our existence here is the punishment?
-
would be nice if there was a link for this
Like the one in the arrow at the top of your post, next to the avatar of the person you are replying to?
-
Yes, I noticed that.
Taking my post (using the ) you get https://what.thedailywtf.com/t/eval/50650/187?u=loose, which I take to be a link to the post - as designed.
Hovering over the in the same post I get https://what.thedailywtf.com/t/eval/50650/187 in the Browser status bar and in reality (i.e right-click/copy link address) rather than the intuitive and expected link to "the post".
What I expected was https://what.thedailywtf.com/t/eval/50650/69?u=loose to take me back to the post so that I could see the post in the context of those around it.
I will admit that I have never clicked that link, and having now clicked it I can see how it works and I can see how it might help in a very confusing way (for me at least). It's like a reverse of the "Reply" thingy but failing (for me).
General Note: For some strange reason, I always actively enable the Status Bar of any Browse I use, and use it to constantly check / be aware of what is "under" my point and where it goes.
But as I often try point out to others, beware of assumptions as they are a to learning.
Thank you for making me do this :)