Sponsored by Realtor.com
Top 50 Most Christmassy City Names view!
realtor.com - Put yourself in a holiday mood by reading about these cities and towns with festive names.
39 Comments
- vidberg, on 10/12/2007, -11/+42Before discussions start, let me point out for those that are still ignorant of this fact...
JAVASCRIPT IS NOT JAVA - tuna1, on 10/12/2007, -2/+17"Step 1: Keep Your Syntax and Structure Clean and Logical"
HA!
Spagetti code == job security - inactive, on 10/12/2007, -2/+15These are very basic coding practices that apply to any language and _should_ be a natural habit of any half decent programmer.
- inactive, on 10/12/2007, -1/+12The logic behind that is if you want to at a later date add something to the print experience across the entire site. No inline references to window.print() means everything can be routed through another page, or whatever in the future.
- mikechml, on 10/12/2007, -4/+13It recommends to separate code into functions, but isn't this going too far?
function printWindow(){
window.print();
}
function closeWindow() {
window.close();
} - jo42, on 10/12/2007, -3/+11Exactly. Nothing new here. Move along.
- jokerr, on 10/12/2007, -1/+7Agreed. These steps are obvious. Write clean code, comment your code, break code up into functions, use variables instead of literals, blah blah blah. These are basic practices.
- ahawks, on 10/12/2007, -2/+7It seems silly, but it's actually sort of foward-thinking. The first reason doesn't necessarily apply to JavaScript, but say you wanted to replace the UI with another language (ie, port from Windows to GTK or something). The rest of the code can still call closeWindow(), but you can have a check for the platform to depend on what real function to call.
The other reason I can think of, which is pretty similar, only it DOES apply to JavaScript is if you want to change the functionality of closing a window later on. For example, always save the session data to a cookie or something before closing the window. A common function to add to a simple procedure is logging. Using a wrapper, you could send a quick message to the server telling it the window was closed.
Besides, what harm does it do to add a layer of abstraction? - DCstewieG, on 10/12/2007, -1/+4I like to enforce out-forcing.
- tony23, on 10/12/2007, -2/+5@pkulak -
If you think "everyone knows that", you haven't been on a javascript discussion forum lately! - ell0bo, on 10/12/2007, -0/+3yes, this is a bit anal, but when you take it one level out more:
function WindowController(){
this.printWindow = function(){
window.print();
}
this.closeWindow() = function{
window.close();
}
}
Then it actually makes more sense to break everything up. As he talks about in the article, it's sometimes good to break things into objects, and when you do that, it's better to then have those seperate functions. Now, would I ever do this in this instance, heck no, but it does prove a point.
Go OO JavaScript (as close as you can get) and nice to see it coming from another Heilman(n)
-edit: nice point kweeket, missed that on first look - kweeket, on 10/12/2007, -0/+2I thought it was overkill too at first, then saw that he was using this function
function createLink(url,text,func)
and passing in the function names printWindow and closeWindow as the func parameter. So it's actually a pretty nice way of doing it. - Phaedruss, on 10/12/2007, -2/+4Besides, who is going to hire someone named "tuna1" in the first place?
- bpapa, on 10/12/2007, -0/+2I think some day I am going to write a blog entitled "programming tips for language." And then, in the article, I am gonna say "well I would write some tips down, but all the commens on Digg will be 'LOLZ THIS IS BASIC I KNEW IT ALREADY EVERYBODY DOES' so I just won't bother."
Some day I'll do that, I promise. - tuna1, on 10/12/2007, -1/+3Its a joke. If my potential employer couldn't see that, then I wouldn't want to work for them anyways.
- benw, on 10/12/2007, -0/+2Did the writer of this article think he was contributing something new here?
"Keep Your Syntax and Structure Clean and Logical" BLIMEY! There's a revolutionary idea!
"Comment your code" He's not even trying. This is bog-standard How To Write Good Code. What a waste of space. - codepo8, on 10/12/2007, -0/+1To those "discussing" this article here: Please take the following part fully into consideration:
--- snip ---
Yes, some of the steps may be very obvious to the jet-set, well travelled and seasoned JavaScript developer, but it can’t hurt to remind ourselves of their virtues.
Furthermore, I dare any one of you to look at some older code and test it against them [...] Scope and feature changes together with looming deadlines and budget cuts breed bad code; it is a fact of software development.
--- snap ---
You are right that there is not much new here and that these principles can be applied to any programming language. The difference with JavaScript is that for almost a decade not many people took JS serious enough to apply them, and now we have to wade through lines and lines of unreadable code.
The other aspect is that JavaScript is a language that attracts a lot of developers that don't have a programming background, as it allows you to create visual effects and ties in very closely with CSS and HTML. Never assume that everybody knows what you know and things are as obvious. - pkulak, on 10/12/2007, -5/+6I'm digging it down because everyone already knows that. I think in 1999 my grandmother was a litle confused, but that's it.
- armbar, on 10/12/2007, -0/+1"Who is going to hire someone named tuna1 in the first place?"
The same person picking up someone named "Phaedruss"? - hansamurai, on 10/12/2007, -0/+1Having just attended an hour long meeting on the future of just one of our Java files, these rules pretty much hold up for any language. Great collection. Digg.
- Majdaa, on 10/12/2007, -0/+1Fantastic site, how did i not know about it? most definately going on my bookmark toolbar folder.
Really nice design and implementation, i was more impressed with the actual site than the article... - fquednau, on 10/12/2007, -0/+1Woa, that thing above should have gone to http://digg.com/design/Dvorak_Why_CSS_Bugs_Me...
The text here was much more likeable - Dotnetsky, on 10/12/2007, -0/+1I haven't read it yet, but judging from the comments above it's nice to see something like this made it to the front page instead of the mindless script-kiddie crap I usually see there.
- fquednau, on 10/12/2007, -0/+1This is a lax piece of write-up and should be categorised as rant. It offers nothing and then less. Cascading is much like inheritance, altough admittedly you haven't a lot of control about it. A controlled way of inheritance may have been nicer, but I find the cascading way of things relatively manageable (although, again, I never go wild on design features). He must have tried to do some cross-browser feats shortly before writing that, LOL!
The only thing I find sad is that CSS syntax is not XML. - resim, on 10/11/2007, -0/+0i think fantastic site www.soaringmedia.com
- GRoper, on 10/12/2007, -0/+0In the article Chris Hellman states:
%u201CNOSCRIPT is greaceful(sic) degredation(sic) whereas we should think in terms of progressive enhancement - building for the future rather than for the past.%u201D
But his example does not work at all if javascript is disabled. That is not graceful degradation, that is failure!
When developers modify the basic WWW GUI, the result is chaos: every site is different and each has different navigation rules and interactions. Users must be trained for each site.
Best is to not use javascript and fall back to the default WWW browser behaviors. In the long run that is also most efficient, since once latency decreases sufficiently, it does not matter whether processing is done on the client or the server (IIRC the Devil Himself, Bill Gates, said the same years ago). - tuna1, on 10/12/2007, -1/+1"Besides, who is going to hire someone named "tuna1" in the first place?"
People who don't discriminate by user names. - codepo8, on 10/12/2007, -0/+0Read my comment there and stop playing the wiseman here. Your comment shows that you didn't check the code at all and you don't seem to have grasped the idea of progressive enhancement.
- MrMidi, on 10/12/2007, -0/+0@lhenkel
HA!!! 10,000 diggs to you - GRoper, on 10/12/2007, -0/+0I _had_ checked the code and found that, when javascript is disabled, the user is blocked from the application.
That is not "graceful degradation" ; that is termed "application failure".
Best to not write apps that depend on javascript. Better yet, don't write apps that _use_ javascript, because they will soon be an unnecessary hindrance. - borchard76, on 10/12/2007, -3/+2Well, you sure know how to make sure no one hires you. If any potential employer sees that you'll fail that job interview (unless they like that, in which case, WHY do you want to work for them?).
- jokerr, on 10/12/2007, -2/+1Spaghetti code can be good job security and is an easy way to ensure that people will have a hard time deciphering it (Google javascripts anyone?). Just remember, it could always come back to haunt you.
- lhenkel, on 10/12/2007, -1/+0while (diggArticles) {
if ((articleTitle.indexOf('AJAX')) or (articleTitle.indexOf('Ubuntu'))) {
print "Why do articles about AJAX and Ubuntu always make the front page?!";
}
imbecilicCommentDestinedToBeDuggDown ();
imelite();
beenThereDoneThat();
}
function imbecilicCommentDestinedToBeDuggDown () {
print "This is part of the homosexual/jewish conspiracy! We should kill puppies!";
}
function imelite() {
print "This is too basic; everyone with half a brain knows that";
}
function beenThereDoneThat() {
print "This has been around forever. Why does Digg recycle this stuff?";
} - greasytony, on 10/12/2007, -2/+0If you're the only person who fix your code cos it's all spaghetti, you will in a way be indespensible!
A lot of bosses, especially new bosses, like to get rid of all indispensible employees asap!
If you, being indispensible, are not available in an emergancy, the company's in trouble. - codepo8, on 10/12/2007, -6/+4Java is to JavaScript what car is to carpet
- benw, on 10/12/2007, -5/+2Why do you imagine it makes a difference to how this article is received? The fact that this is a collection of warmed-over, done-to-death, basic advice that all developers should know is why the article sucks. The fact that Javascript and Java are entirely unrelated languages has absolutely nothing to do with why the article sucks.
- bobbygreer, on 10/12/2007, -5/+1This is an awesome way to in-force least privilege in code. In my mind, that is extremely good practice even though it uses up extra space and in excess could affect load times. Not realistically however.
- inactive, on 10/12/2007, -10/+4We're digging you down because you suck. That and the article, which you obviously didn't read, is not even particularly about JavaScript, it is about (very) basic good programming habits.
I'm guessing JavaScript was thrown in just so AJAX could be too. - vidberg, on 10/12/2007, -21/+6People digging this down, do you think Javascript is Java?


What is Digg?