Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Javascript (http://www.velocityreviews.com/forums/f68-javascript.html)
-   -   What is a software engineer? (http://www.velocityreviews.com/forums/t939859-what-is-a-software-engineer.html)

David Mark 11-14-2009 08:38 PM

What is a software engineer?
 
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. ;)

Eric Bednarz 11-14-2009 09:33 PM

Re: What is a software engineer?
 
David Mark <dmark.cinsoft@gmail.com> writes:

> What is a software engineer?


In the Netherlands at the time of writing, anything from a computer
science graduate to a HTML/CSS code monkey who can copy and paste
[insert javascript[insert naming controversy here] library name
here]-code.

David Mark 11-14-2009 10:09 PM

Re: What is a software engineer?
 
On Nov 14, 4:33*pm, Eric Bednarz <bedn...@fahr-zur-hoelle.org> wrote:
> David Mark <dmark.cins...@gmail.com> writes:
> > What is a software engineer?

>
> In the Netherlands at the time of writing, anything from a computer
> science graduate to a HTML/CSS code monkey who can copy and paste
> [insert javascript[insert naming controversy here] library name
> here]-code.


And at the time of this writing, a "proof" seems to be any bullshit
pattern you can observe and report with your installed browser(s).
It's like, if you saw it on the monitor, it must be true. Or more
like if _anyone_ ever reported it.

It is my contention that browsers (especially modern browsers) are not
mysterious, illogical creatures to be observed. Neither are the
people that make them. :)

Thomas 'PointedEars' Lahn 11-14-2009 10:12 PM

Re: What is a software engineer?
 
David Mark wrote:

> 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.


Without trying to justify their response, when analyzing this problem I
think it is important to take a step back and understand that very much
depends on one's position in the learning curve and one's level of
experience in the field. It is also a matter of the methodology chosen to
employ in order to learn (a new programming language), which is strongly
related to the two former aspects.

If you do not know the difference between native objects and host objects
(perhaps because you chose to learn by example only), and the possible
difference in behavior that this involves, you do not get the idea of using
an alternative to a type-converting test. And if you have never seen the
type-converting test to fail, but you have seen some environments to expose
an eval() method (and never a non-function `eval' property) on Window
instances and others to have no such property, but an eval() method
elsewhere instead, you can get the idea that this test was a good idea.

Of course, that eval() is primarily a method of the ECMAScript Global Object
and that therefore the wrapper is either unnecessary or error-prone, can
already be ascertained by reading the first page of the Netscape/Mozilla.org
Core JavaScript Reference┬╣, so the person's position in the learning curve
and level of experience must be assessed as being rather early and low.

As Richard stated more aptly before, the main problem with people learning
JS/ES is extreme, objectively unjustified overconfidence; the languages are
so dynamic in nature and the results of their application in a browser
immediately visible that they appear too easy to learn from so-called
tutorials (written by usually equally inexperienced individuals) instead of
the -- to some apparently more painful -- process of RTFM. (This goes
especially with the ignorance of the difference between ECMAScript,
JavaScript, JScript, and the many other ECMAScript implementations and their
versions, which is seldom, if ever, even mentioned in tutorials and books
intended for learners.)

Quick successes with superficial tests in a handful of browsers, inexact or
bogus (script-kiddie) terminology employed by people at approximately the
same position of the learning curve, suggest to the uninitiated that this
simple appearance would be true, that the complexity the other people are
talking about does not exist at all, and that those are just blowing up
their egos. So these people tend to become victim to the fallacy of
shifting the burden of proof, asking "show me where it fails", falsely
assuming that failure would be the exception without recognizing for an
instant (until told, but sometimes not even after that) that the approach is
destined to fail (as Specifications are written to adhere to them) and that
its working is the (fortunate?) exception instead.

> How about this one:-
>
> if (typeof xyz == 'array' || xyz instanceof Array) {
> ...
> }
>
> First test is _never_ true in an ECMAScript implementation.


That is not quite correct. The first test could result in `true' in a
conforming implementation of ECMAScript if `xyz' referred to a host object.
But I doubt the person writing it was aware of that or even intended to meet
the case.

> 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?


As for the frames argument, if you never used this code cross-window or
cross-frame, you probably would never notice the difference. That is what
happened to me, and I am not too proud to admit that it took me reading
replies in this newsgroup a few months ago to see the problem, even though
my code uses the `constructor' property instead as I considered it more
compatible. And the library providing the testing function (but AFAIK not
using it for crucial functionality) existed in that form since approximately
*5 years* before that!

> 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?


Probably not; at least I would try to implement a version that eases the
transition to a better approach.

However, if you are inexperienced enough it is too easy to attribute
problems newly discovered only in one or a few runtime environments to a bug
in those environments. The misconception so built is understandable, but
not acceptable, of course.


HTH :)

PointedEars
___________
┬╣ However, the current Reference says "JavaScript functions not associated
with any object" which is wrong, and "In the ECMAScript specification,
these functions are referred to as methods of the global object." which
is misleading with regard to the former sentence. Because in
Netscape and Mozilla.org JavaScript, among other implementations, too,
these functions are methods of the global object, and knowing that is a
requirement for writing a sufficiently reliable feature test for those
methods.
--
Anyone who slaps a 'this page is best viewed with Browser X' label on
a Web page appears to be yearning for the bad old days, before the Web,
when you had very little chance of reading a document written on another
computer, another word processor, or another network. -- Tim Berners-Lee

David Mark 11-14-2009 10:30 PM

Re: What is a software engineer?
 
On Nov 14, 5:12*pm, Thomas 'PointedEars' Lahn <PointedE...@web.de>
wrote:
> David Mark wrote:
> > 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.

>
> Without trying to justify their response, when analyzing this problem I
> think it is important to take a step back and understand that very much
> depends on one's position in the learning curve and one's level of
> experience in the field. *It is also a matter of the methodology chosento
> employ in order to learn (a new programming language), which is strongly
> related to the two former aspects. *
>
> If you do not know the difference between native objects and host objects
> (perhaps because you chose to learn by example only), and the possible
> difference in behavior that this involves, you do not get the idea of using
> an alternative to a type-converting test. *And if you have never seen the
> type-converting test to fail, but you have seen some environments to expose
> an eval() method (and never a non-function `eval' property) on Window
> instances and others to have no such property, but an eval() method
> elsewhere instead, you can get the idea that this test was a good idea.
>
> Of course, that eval() is primarily a method of the ECMAScript Global Object
> and that therefore the wrapper is either unnecessary or error-prone, can
> already be ascertained by reading the first page of the Netscape/Mozilla.org
> Core JavaScript Reference╣, so the person's position in the learning curve
> and level of experience must be assessed as being rather early and low.


Yes, the (unjustified) thinking goes that calling eval as a method of
the Global object (or a host object) will set the - this - identifier
and scope accordingly. But the logic is broken in any event as - eval
- certainly won't do that. Unless the aim is for cross-browser chaos,
it's a one-liner in need of a do-over.

[...]

>
> > How about this one:-

>
> > if (typeof xyz == 'array' || xyz instanceof Array) {
> > * * ...
> > }

>
> > First test is _never_ true in an ECMAScript implementation.

>
> That is not quite correct. *The first test could result in `true' in a
> conforming implementation of ECMAScript if `xyz' referred to a host object. *


Fair enough. Should point out that - for host objects - it could just
as easily be 'mickeymouse'.


> But I doubt the person writing it was aware of that or even intended to meet
> the case.


Definitely not. It's paired with instanceof Array and roughly the
same mistake I fixed (by proxy) in jQuery two years ago.

David Mark 11-14-2009 10:49 PM

Re: What is a software engineer?
 
On Nov 14, 5:12*pm, Thomas 'PointedEars' Lahn <PointedE...@web.de>
wrote:

[...]

>
> Of course, that eval() is primarily a method of the ECMAScript Global Object
> and that therefore the wrapper is either unnecessary or error-prone, can
> already be ascertained by reading the first page of the Netscape/Mozilla.org
> Core JavaScript Reference╣, so the person's position in the learning curve
> and level of experience must be assessed as being rather early and low.
>


True, but beside the main point I was trying to illustrate with this
(bad) example. This is just as illogical a design:-

var GLOBAL = this;

var myEval = function(str) {
return GLOBAL.eval ? GLOBAL.eval(str) : eval(str);
};

....though a tiny bit closer to competent. I made my example doubly
bad. The point is that there is no way this could be counted on to
evaluate script with global scope. In short, by design, some
percentage of browsers will not be able to - for one - declare global
variables. As written, resolving - str - will be an adventure as well.

Garrett Smith 11-14-2009 11:19 PM

Re: What is a software engineer?
 
David Mark wrote:
> 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).
>


Object.prototype.eval was removed from Spidermonkey in 2007, IIRC.

I believe that in the case where Object.prototype.eval is implemented
(nonstandard), the |this| value is Base object (window here).

I never relied Object.prototype.eval, so the quirks of that are not
something I attach much value to (worth forgetting).

IIRC jquery uses window["eval"] in the source code. looking...

hat rack:
| // Get the JavaScript object, if JSON is used.
| if ( type == "json" )
| data = window["eval"]("(" + data + ")");

Not sure why they chose that approach over:
data = eval("(" + data + ")");

That approach uses indirect eval. The calling context's scope is used,
so is just as unsafe in that regard. Only difference is older
implementations' thisArg is different.

It indirect eval, for reasons I'm failing to comprehend.

I believe I mentioned this very issue about a year or so ago on the
jquery newsgroup.
--
Garrett
comp.lang.javascript FAQ: http://jibbering.com/faq/

David Mark 11-14-2009 11:35 PM

Re: What is a software engineer?
 
On Nov 14, 6:19*pm, Garrett Smith <dhtmlkitc...@gmail.com> wrote:
> David Mark wrote:
> > 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).

>
> Object.prototype.eval was removed from Spidermonkey in 2007, IIRC.
>
> I believe that in the case where Object.prototype.eval is implemented
> (nonstandard), the |this| value is Base object (window here).
>
> I never relied Object.prototype.eval, so the quirks of that are not
> something I attach much value to (worth forgetting).


Definitely.

>
> IIRC jquery uses window["eval"] in the source code. looking...
>
> hat rack:
> | // Get the JavaScript object, if JSON is used.
> | if ( type == "json" )
> | * data = window["eval"]("(" + data + ")");
>
> Not sure why they chose that approach over:
> * *data = eval("(" + data + ")");


Voodoo.

David Mark 11-15-2009 03:48 AM

Re: What is a software engineer?
 
On Nov 14, 10:17*pm, "Richard Cornford" <Rich...@litotes.demon.co.uk>
wrote:
> Thomas 'PointedEars' Lahn wrote:
> > David Mark wrote:

> <snip>
> >> How about this one:-

>
> >> if (typeof xyz == 'array' || xyz instanceof Array) {
> >> * * ...
> >> }

>
> >> First test is _never_ true in an ECMAScript implementation.

>
> > That is not quite correct. *The first test could result in `true'
> > in a conforming implementation of ECMAScript if `xyz' referred to
> > a host object. But I doubt the person writing it was aware of
> > that or even intended to meet the case.

>
> <snip>
>
> That "could result in 'true'" is very much a theoretical possibility; a
> host object may result in any string when - typeof - is applied to it,
> but it is extremely rare that they do result in anything that is not
> already in the ECMAScript list, and the exception ('unknown' in IE when
> testing ActiveX objects, methods and properties) is literally the only
> one that I have ever encountered, or heard tell off.


That's be

>
> Personally, I don't believe that there has ever been a browser
> environment in which any object (host or otherwise) resulted in 'array'
> when - typeof - was applied to it. I think that is formulation (and the
> many similar - typeof - tests) is just another of those mystical
> inactions that start out as someone's mistake and propagate precisely
> because they are essentially harmless (the 'array' result never happens
> and so the code guarded by it is either unconditionally executed or not
> executed).
>
> That is probably the measure of an 'engineer' in this context; an
> engineer would want to identify and eliminate the mystical incantations
> from what they were doing.
>


It seems some are unsure how to identify mystical decision decisions.
There is this "show me" attitude that seems to reduce programming to
observation. The programmer role is reduced to one who can observe
patterns, rather than one who can understand abstractions. And, as
mentioned, this is one bug that will never "show" its face (and is
actually just an ineffectual waste of space and a telltale sign of the
author's spot on the JS learning curve).

But this attitude becomes dangerous on more critical design
decisions. I've heard talk of a script loading mechanism that will
rely solely on the non-standard onreadystatechange and onload
properties of created SCRIPT elements. The plan is to inject SCRIPT
elements directly into the HTML element and then rely on the non-
standard events to fire and put everything in order. ISTM that
relying on observations of these two hacks working together in a
limited set of present environments is folly. Furthermore,
investigating its viability by searching for an environment that fails
is a waste of time (i.e. what does it prove if one can't be found?)
and a backwards approach to browser scripting. I think an engineer
would dismiss the fantasy scenario(s) out of hand and think about
better alternatives with at least some basis in present reality and/or
tradition in history.

Can you imagine if C++ - for example - were written like this? It
would actually be easier in some respects. Trying to script browsers
by feel seems like Mission Impossible by comparison (and perhaps
that's why so many involved with JS consider it impossible).

David Mark 11-15-2009 05:08 AM

Re: What is a software engineer?
 
On Nov 14, 11:55*pm, "Richard Cornford" <Rich...@litotes.demon.co.uk>
wrote:
> Richard Cornford wrote:
> > ... After all, you can show them the environments where
> > objects result in 'undefined'...

>
> That 'undefined' should have been 'unknown', but you probably figured
> that out already.
>


Actually, I thought you meant document.all in FF quirks mode. ;)



All times are GMT. The time now is 04:26 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.