News for hackers. Stuff that matters.
Re:Rick Santorum's Fake Donation Meter by Osiris on Friday May 25, 2012 @06:00PM (#4025526)
I find it most disturbing that they are polluting the global namespace with all those variables and functions. Don't JavaScript developers these days understand how to properly scope their JavaScript?
Re:Rick Santorum's Fake Donation Meter by Deestan on Friday May 25, 2012 @07:07PM (#4025746)
As long as it's "single page bound" JS like this, I honestly don't think it matters one bit.

Reusable components and utility libraries is something different, of course.

Re:Rick Santorum's Fake Donation Meter by sjs on Friday May 25, 2012 @08:29PM (#4025964)
It's still incredibly error prone and just bad practice. It's a telltale sign of a bad developer because a good dev would instinctively just use var without thinking about it. Good devs may make a mistake here or there but this is clearly well beyond a forgotten var keyword.
Re:Rick Santorum's Fake Donation Meter by slantyyz on Friday May 25, 2012 @09:40PM (#4026115)
>> It's a telltale sign of a bad developer

I'm just guessing, but the site was probably not developed by a technical team, probably some web shop that specializes more on the design/layout/content side and not on the JS side.

So it's likely it's the work of a non-developer than a bad developer. The net result is the same (bad code) but the distinction is that the code was possibly written by someone who wouldn't even be considered a developer.

Re:Rick Santorum's Fake Donation Meter by aaronasterling on Friday May 25, 2012 @08:34PM (#4025978)
But when writing code, how do you know that it's always going to be "single page bound"? YAGNI is frequently useful poison and nothing more. When it's so easy to do it right the first time, why not?
Re:Rick Santorum's Fake Donation Meter by Deestan on Saturday May 26, 2012 @10:22AM (#4027335)
> When it's so easy to do it right the first time, why not?

a) Because it isn't "right" as such. It's just "better" if the code is going to be reused. Which it isn't.

b) The code style serves as documentation. I can clearly read from this code that it's not a reusable component. It is now easier for me to get an idea of how and where this code is being used in the site.

c) Personally, I'm wary of "pre-emptive generalization". Every layer of abstraction makes the code slightly less readable. Also, unless there exists at least two use cases right now, you're not likely to get the reusability right anyway.

Re:Rick Santorum's Fake Donation Meter by adrianparsons on Friday May 25, 2012 @06:07PM (#4025558)
I like that bad namespacing is what you find disturbing here.
Re:Rick Santorum's Fake Donation Meter by hrabago on Friday May 25, 2012 @06:19PM (#4025602)
I can't help it. It's just the way I'm wired.
Re:Rick Santorum's Fake Donation Meter by shaggyfrog on Friday May 25, 2012 @06:08PM (#4025563)
Are you really asking why a developer tasked with creating something intentionally deceptive didn't use best practices? I'm thinking not a lot of care or attention to anything was paid that day.
Re:Rick Santorum's Fake Donation Meter by UnFleshedOne on Friday May 25, 2012 @06:53PM (#4025705)
Different kind of ethics: "It should be noted that no ethically-trained software engineer would ever consent to write a DestroyBaghdad procedure. Basic professional ethics would instead require him to write a DestroyCity procedure, to which Baghdad could be given as a parameter." (lost the source of the quote)
Re:Rick Santorum's Fake Donation Meter by MBlume on Friday May 25, 2012 @07:11PM (#4025758)
http://en.wikiquote.org/wiki/Nathaniel_Borenstein

To understand how these problems can be addressed, it is instructive to consider an analogy. Imagine, for a moment, that somewhere in the basement of the Pentagon there are two computers. They are identical hardware, and they run identical software; they are as alike as two peas in a pod. On each of them, there is an executable procedure called "DestroyBaghdad". On one of the machines, executing this procedure does nothing. On the other, the effects of executing the procedure are disastrous, at least for the citizens of Iraq. The only difference between the two machines is a single wire coming out of the back of the second machine.[1]

The point, of course, is that nothing inherent to a computational language is dangerous; danger is posed only insofar as the effects of executing statements in a language include "side-effects" in the external world. If all the "wires" connecting a computational language to the outside world are cut, then executing programs in that language is harmless. (An exception to this claim is that such a program can still tie up the CPU, virtual memory, or swap space on a machine by going into an infinite loop; this can be handled via resource limitations.)

[1]It should be noted that no ethically-trained software engineer would ever consent to write a "DestroyBaghdad" procedure. Basic professional ethics would instead require him to write a "DestroyCity" procedure, to which "Baghdad" could be given as a parameter.

http://www.guppylake.com/~nsb/CSCW-ATOMICMAIL.txt

Re:Rick Santorum's Fake Donation Meter by ryanac on Friday May 25, 2012 @07:12PM (#4025760)
Had me laughing so I tried to find it: http://en.wikiquote.org/wiki/Nathaniel_Borenstein
Re:Rick Santorum's Fake Donation Meter by zerostar07 on Friday May 25, 2012 @06:12PM (#4025576)
Probably wanted to make it more readable, it's not even minified.
Re:Rick Santorum's Fake Donation Meter by artursapek on Friday May 25, 2012 @06:17PM (#4025590)
I don't think a JSLint-compliant, file-minifying developer would need to resort to this kind of work.
Re:Rick Santorum's Fake Donation Meter by zerostar07 on Friday May 25, 2012 @06:57PM (#4025719)
I 'm implying s?he did it on purpose to shame his/her bosses.
Re:Rick Santorum's Fake Donation Meter by artursapek on Friday May 25, 2012 @07:02PM (#4025734)
Ah, perhaps this is the case. Would have been fun to stumble across a "Help, I'm trapped in a bullshit factory!" comment or something. But that would not help one's career.
Re:Rick Santorum's Fake Donation Meter by luigi on Friday May 25, 2012 @06:15PM (#4025582)
I find the 8 space indentation most disturbing.
Re:Rick Santorum's Fake Donation Meter by hrabago on Friday May 25, 2012 @06:18PM (#4025597)
It's the Tab character.
Re:Rick Santorum's Fake Donation Meter by luigi on Friday May 25, 2012 @06:23PM (#4025613)
Ah, so it is. Then I'm disturbed that browsers render a tab as 8 spaces.
Re:Rick Santorum's Fake Donation Meter by Zirro on Friday May 25, 2012 @06:31PM (#4025648)
https://developer.mozilla.org/en/CSS/tab-size was just implemented in the newest browsers, for all your tab-sizing needs :)
Re:Rick Santorum's Fake Donation Meter by hrabago on Saturday May 26, 2012 @04:40PM (#4028297)
8 is the traditional size of tabs though, isn't it? Seems like a reasonable default. That's partially why some teams (mine included) discourages the use of tabs in source code - its appearance varies depending on what's rendering it, affecting code readability.
Re:Rick Santorum's Fake Donation Meter by cpeterso on Friday May 25, 2012 @06:38PM (#4025669)
Patches accepted!
Re:Rick Santorum's Fake Donation Meter by stevewilhelm on Friday May 25, 2012 @07:59PM (#4025891)
Was just looking at namespace best practices today for a utility library I was implementing. Is there a defacto standard?
Re:Rick Santorum's Fake Donation Meter by aaronasterling on Friday May 25, 2012 @08:43PM (#4025998)
The defacto standard is to put nothing in an enclosing namespace unless it's needed there. The purpose of functions (especially in a language like JS) is to wrap up everything that's needed to accomplish a given task and leave no mess behind.
Re:Rick Santorum's Fake Donation Meter by entropy_ on Saturday May 26, 2012 @02:18AM (#4026676)
Then why oh why are variables global by default? (this is not meant as an attack on your point, I fully agree, I just find this awfully frustrating about JS. Sane languages have scoped by default and a global keyword, not the other way around)
Re:Rick Santorum's Fake Donation Meter by aaronasterling on Thursday May 31, 2012 @06:16PM (#4050693)
You'd have to ask its designer. Sloppy programmers do like globals and JS was targeted for them.
Re:Rick Santorum's Fake Donation Meter by wavephorm on Friday May 25, 2012 @07:12PM (#4025761)
The web developers they hired were liberal.