D
David Mark
What is a software engineer? I talked to a group recently and
presented this pattern:
var myEval = function(str) {
return window.eval ? window.eval(str) : eval(str);
};
I know a lot of programmers of various degrees of proficiency read
this group. Can anyone not see the problem with this in the second it
takes to read it?
Even if you don't know the language, but know that the code must be
executed in various environments (which may or may not feature an eval
method on host objects), logic dictates that this is about as bad as a
design can get (designed to give varying cross-browser results).
Would you hang your hat on this? I've been asked by these engineers
to "prove" that this is a bad idea (I say the proof is right there in
the code). They say they've never _seen_ it fail. For this one, I
don't know what that means (it's obviously designed to fail). So when
did programming becomes a process of gathering empirical evidence, as
opposed to understanding logic? Seems like browser scripting would be
the worst discipline for such a change in strategy.
How about this one:-
if (typeof xyz == 'array' || xyz instanceof Array) {
...
}
First test is _never_ true in an ECMAScript implementation. Same
engineers want "proof" of that too. (proof that something does not
exist!) Second test is known to be inconsistent due to frames. Is it
really possible to program JS and not know these things?
By the same token, what if you had wrappers for get/set/hasAttribute
that made little or no attempt to deal with the broken MSHTML
implementations (e.g. jQuery), built a CSS selector engine on top of
them and found out years later that you made a *huge* mistake. You
can see all of the support tickets that have come up over the years
because of this mistake. Would you leave all of the bugs in place for
the sake of some perverse form of backwards compatibility?
These are all lynchpin functions. It boggles my mind that people
could rely on (and waste time maintaining) code like this for
absolutely everything, with the only understanding being that it "just
works" (despite the fact that it is patched constantly, especially
when new browsers emerge).. I guess thousands of similarly challenged
engineers can't be wrong.
presented this pattern:
var myEval = function(str) {
return window.eval ? window.eval(str) : eval(str);
};
I know a lot of programmers of various degrees of proficiency read
this group. Can anyone not see the problem with this in the second it
takes to read it?
Even if you don't know the language, but know that the code must be
executed in various environments (which may or may not feature an eval
method on host objects), logic dictates that this is about as bad as a
design can get (designed to give varying cross-browser results).
Would you hang your hat on this? I've been asked by these engineers
to "prove" that this is a bad idea (I say the proof is right there in
the code). They say they've never _seen_ it fail. For this one, I
don't know what that means (it's obviously designed to fail). So when
did programming becomes a process of gathering empirical evidence, as
opposed to understanding logic? Seems like browser scripting would be
the worst discipline for such a change in strategy.
How about this one:-
if (typeof xyz == 'array' || xyz instanceof Array) {
...
}
First test is _never_ true in an ECMAScript implementation. Same
engineers want "proof" of that too. (proof that something does not
exist!) Second test is known to be inconsistent due to frames. Is it
really possible to program JS and not know these things?
By the same token, what if you had wrappers for get/set/hasAttribute
that made little or no attempt to deal with the broken MSHTML
implementations (e.g. jQuery), built a CSS selector engine on top of
them and found out years later that you made a *huge* mistake. You
can see all of the support tickets that have come up over the years
because of this mistake. Would you leave all of the bugs in place for
the sake of some perverse form of backwards compatibility?
These are all lynchpin functions. It boggles my mind that people
could rely on (and waste time maintaining) code like this for
absolutely everything, with the only understanding being that it "just
works" (despite the fact that it is patched constantly, especially
when new browsers emerge).. I guess thousands of similarly challenged
engineers can't be wrong.