The Javascript cargo cult (40)

1 Name: !WAHa.06x36 2005-04-08 23:55 ID:+BlKUASR

There is something very strange about Javascript. It's not the language itself, which is fairly elegant and capable. It is the programming community around it.

Recently, I've been getting more and more frustrated when trying to find information about Javascript online. With most any other language, you can throw in a few well-chosen keywords in Google - a function name, an object name and method - and you'll pick up one or another form of documentation of reference that explain the usage of this language construct. Not so with Javascript. You find script archives, code snippets, cute little bunnies jumping across your screen - anything but factual information.

Essentially, most people using the language are simply cut-and-pasting code. Nowhere is there any actual insight into the language concepts used, or the algorithms, or anything beyond making bunnies jump across your screen. Horribly inefficient and ugly codes gets cut-and-pasted from page to page, and never once is it modified, optimized or questioned in any way. These code snippets have been passed down from the Gods in their huge flying machines, and are to be revered and never doubted.

Somewhere in this jungle, I'm sure there are people who know what they're doing. But they are few and far between, and don't seem to be very interested in sharing their insights - not necessarily out of malice - they may just be too few to make any sort of organized efforts. There DOES exist actual documentation - after much searching, I did manage to find the Javascript language specs to answer a fairly basic question none of these cargo-cult websites would probably even have understood.

However, recently, a shining beacon of enlightened reason has appeared in this fog bank of xerox mentality: Google seems to have collected a huge amount of people who actuall understand Javascript code, and have by their example shown that the language actually can do. The XMLHttpRequest object, that I myself have been using for several different projects to great effect, has existed in Javascript implementation for quite some time now, but not until Google actually showed people that it exists and can be used has anyone even touched it.

Fuck's sake, I'm tired.

2 Name: Sling!XD/uSlingU 2005-04-09 00:24 ID:+/EgLPCG

(Assuming your analysis is correct, I haven't checked:)
In the days when Google didn't exist and Altavista was king, it was the reverse: you couldn't help but fall over Javascript documentation pages everywhere. Netscape had an extensive documentation online. But example code snippets were scarce.

3 Name: Simon 2005-04-10 04:58 ID:Heaven

Yes, all the online stuff does suck, so you need to get an actual book. Buy yourself a copy of JavaScript: The Definite Guide. The Javascript & DHTML Cookbook is also pretty decent.

4 Name: !WAHa.06x36 2005-04-10 10:55 ID:+BlKUASR

>>3

You must be some sort of crazy person; I can't Google a book!

5 Name: dmpk2k!hinhT6kz2E 2005-04-10 12:25 ID:lA4k8lpy

#bookz [hint, hint]

6 Name: Sling!XD/uSlingU 2005-04-10 12:28 ID:3Pu67k2K

lol - the other day I was looking for something into a book, and I found myself wishing they had hypertext links in the pages. ^^

7 Name: #!usr/bin/anon 2005-04-11 01:03 ID:J395+Uam

Search for ECMAscript instead of JavaScript and you'll find more factual information. ECMAscript is the 'standard' name. Also, browse around Mozilla's dev pages for interesting programming stuff in JavaScript, since they use it extensively.

8 Name: #!usr/bin/anon 2005-04-13 03:31 ID:Y9BNVRRQ

>>3

That's "JavaScript: The Definitive Guide":
http://www.oreilly.com/catalog/jscript4/

9 Name: Simon 2005-04-16 12:40 ID:Heaven

Whoops, it is too.

10 Name: #!usr/bin/anon 2005-10-03 10:23 ID:7r+13eMN

Apple Developer Connection have some great web dev docs kicking around, which I stumbled across the other day. There's a wealth of interesting JS stuff in there:

http://developer.apple.com/internet/webcontent/index.html

11 Name: #!usr/bin/anon 2005-12-04 00:46 ID:Heaven

A lot of the new Javascript being written is written by people whose primary language is a scripting language (like Ruby, Perl, and Python). The Prototype and Scriptaculous libraries from the Ruby camp are great examples of good programming practices being brought into the Javascript world by outsiders.

http://prototype.conio.net/

http://www.sergiopereira.com/articles/prototype.js.html

12 Name: !WAHa.06x36 2005-12-04 02:28 ID:Heaven

Naming functions $() is good programming practice now? Ack.

There's probably a lot of useful code in there, but I kind of question the wisdom of using a monolithic library in Javascript. You're only going to be using a fraction of that code, but every single visitor is going to download it all anyway.

13 Name: #!usr/bin/anon 2005-12-04 03:27 ID:Heaven

>>12
Given the tools those particular libraries provide, the trade-off is sometimes worth it.

14 Name: #!usr/bin/anon 2005-12-04 16:22 ID:AyeKANQH

>>12
but every single visitor is going to download it all anyway

Oh well! If they don't have broadband by now, screw 'em!

15 Name: #!usr/bin/anon 2005-12-04 17:20 ID:LC0IeJz7

>>14
Totally. And if their browser doesn't do JavaScript at all, really screw 'em.

16 Name: #!usr/bin/anon 2005-12-04 21:24 ID:PqWhOK/O

>>15
It is perfectly possible to write JS that degrades cleanly, and with a good coding environment it won't double your workload.

Every sane web browser supports JS, and that includes some browsers made for disabled people. There are only 3 categories of users without JS:

  • People who suffer from retarded "security" considerations from a clueless IT department, in companies or libraries. Screw 'em for using somebody else's Interweb.
  • 12 or 60 year old UNIX geeks who use Lynx or W3m (even Links/Elinks has some minimal JS support). definitely screw 'em.
  • People who disable it (and therefore can re-enable it) for some reason. They have already considered the pros and cons of disabling javascript, and the fact that JS is more and more used for good and that pop-up blocking and ad-blocking actually works make this position less justifiable everyday. Screw yourself if your website doesn't degrade cleanly without JS, or doesn't provide enough incentive to re-enable JS.

According to stats, they represent 10% of the net. They don't justify not using JS, but they justify making sure the app is usable without JS, even at the cost of a much more clumsier app.

And regarding the size of the file, the last prototype.js ( http://prototype.conio.net/dist/prototype-1.3.1.js ) is 28KB large. Most websites have logos that are much larger than that. It is a very reasonable file size on most websites. Don't forget that you can also compact it (at the cost of obfuscating it and computing power) using a javascript compressor like this one: http://dean.edwards.name/packer/
And don't forget that most browsers accept gzipped content ( http://www.schroepl.net/projekte/mod_gzip/browser.htm )

17 Name: !WAHa.06x36 2005-12-05 17:30 ID:Heaven

> It is perfectly possible to write JS that degrades cleanly, and with a good coding environment it won't double your workload.

I don't really agree. I've written several Javascript apps that would be impossible to write in plain HTML and CGI in any meaningful manner.

However, the fact that I couldn't get it to work in a more limited environment isn't exactly an argument against writing it at all.

18 Name: #!usr/bin/anon 2005-12-05 20:37 ID:PqWhOK/O

>>17
There sure are things that cannot reasonably be done without javascript, but there always is a right thing to do when JS isn't available (in your case, giving a message saying that the app require JS).

The problem is that today we still often see things that completely disregard what happen when JS is turned off, like

 <a href="javascript:window.open('http://example.com', 'popup', 'width=200,height=500')">link</a>

instead of

 <a href="http://example.com" onclick="window.open(this.href, 'popup', 'width=200,height=500'); return false;">link</a>

The sad thing is that most tutorials are still quoting the first one, for the reasons you quoted in >>1

19 Name: Web nazi 2005-12-06 00:59 ID:d7lSp5bj

Indeed. In fact, the first option completely screws the ability to open the link in a new tab, whereas the second option works both ways, which is the main advantage.

20 Name: #!usr/bin/anon 2005-12-30 16:28 ID:Heaven

>>16
Why do you hate people whose preferences are different from yours?

I use w3m because it is the browser I enjoy using the most. I don't discriminate against you because you prefer pretty GUIs. Why should my choice of browser bring this kind of abuse from you?

21 Name: #!/usr/bin/anonymous : 2006-04-26 03:01 ID:eR/zO8Dn

>>18
I just sent an email to a company asking them to use the second type of link instead of the first. Let's see if they listen.

22 Name: 16 : 2006-05-08 03:50 ID:DjlJsH5m

>>20
Because if you enjoy inflicting on yourself the pain that any CLI can be, you definitely can live without the luxury that is javascript. And a lot people using CLI probably don't want it, for social reasons (i.e. lol UNIX fags in their little fantasy land).

Blind people visiting websites made by people like me have it much better than people like you.
People with natural disabilities are much more important than people who inflict the disability upon themselves willingly.

But what I said is not an excuse not to make sure the result is decent with CLI browsers, but the quality gained by accomodating them is not worth the time spent, since there are more naturally disabled users than self-disabled CLI users. (Disabled doesn't means only blind, of course)

23 Name: #!/usr/bin/anonymous : 2006-05-08 13:25 ID:Heaven

A better question is: Why hasn't anyone written a decent command-line browser yet? The ones that exist are still stuck in the nineties.

I guess for the same reason that all command-line text editors are stuck in the seventies.

24 Name: #!/usr/bin/anonymous : 2006-05-08 15:22 ID:eR/zO8Dn

To the best of my knowledge, no command-line browsers exist. w3m, Lynx, and Links are all visual programs, just like emacs and vi.

w3m is actually quite a joy to use. It has tabbed browsing, flexible history, background downloads (even if I suspend it the downloads keep going), bookmarks, gzip encoding support, table rendering, optional frame rendering (it breaks the model of the web, but that's not w3m's fault), the list goes on and on. It's quite modern. In fact when I use a Navigator-style browser like IE or Firefox it feels like going back to the stone age, because in spite of JavaScript, CSS, etc. the UI still sucks so much. Example: Press Back a few times and then follow a new link. Now all your "forward" history is wiped out. Also, these browsers are often unable to do "Back" if it was the result of a form post, and when they can do it, they often reload the page and make you wait. w3m can always go back to old pages, and it doesn't reload unless you ask to.

I can tolerate living without the luxury of things that actually require JavaScript, such as !WAHA.06x36's desktop thing, but when ignorant web designers require JavaScript just to read or submit information, simply because they don't care that not everyone has it, then I get angry. Similarly, I'll use a graphical browser if I want to read webcomics or look at a photo gallery, but when a text-only BBS uses a captcha image, that's really lame. I can save it from w3m and view it, of course, but that's annoying.

As for using software one doesn't like just to impress people, I really doubt anyone does that. Who is going to be impressed? If I chose software for social reasons, I would be using Firefox like all my friends do.

25 Name: #!/usr/bin/anonymous : 2006-05-08 15:46 ID:IczIaZ6R

> Similarly, I'll use a graphical browser if I want to read webcomics or look at a photo gallery,

w3m does support images...
http://img504.imageshack.us/my.php?image=w3mimg9vv.png

> but when a text-only BBS uses a captcha image, that's really lame. I can save it from w3m and view it, of course, but that's annoying.

wakaba/kareha's captchas are funky gifs that w3m (and opera mini) can't display for some reason...
i remember there was something else that had problems with them, too... maybe it was windows preview utility and explorer's thumbnailing? i'm not on a windows machine at the moment and i don't care enough to remote desktop into one to check...

one feature i really like about w3m and miss horribly when i use other browsers: ESC-u Go to relative URL (GOTO_RELATIVE)

26 Name: #!/usr/bin/anonymous : 2006-05-09 17:32 ID:Heaven

> w3m does support images...

I guess my xterm doesn't, then? I'd read it had some sort of image support, but I was never quite sure how that worked.

27 Name: #!/usr/bin/anonymous : 2006-05-09 19:13 ID:IczIaZ6R

>>26
it should work with any xterm. your w3m might be compiled without image support... do w3m -v and see if the output includes "image".

28 Name: #!/usr/bin/anonymous : 2006-05-09 19:15 ID:Heaven

>>27
s/-v/-version/

29 Name: #!/usr/bin/anonymous : 2007-10-13 17:53 ID:oOCO0nIW

Hey I'm bumping this because...

I recently decided to learn a bit of JavaScript, and found lots of useful info, and figured out how to do some neat things very quickly.

So I think the problem >>1 complained about 2 years ago... is solved!

Discuss.

30 Name: #!/usr/bin/anonymous : 2007-10-14 02:36 ID:SwPLUqta

w3m supports images on the framebuffer console too. I nearly jumped out of my chair one day when I was on the text console, ran w3m to visit google and saw the logo up there at the top.

31 Name: #!/usr/bin/anonymous : 2007-10-14 05:41 ID:Heaven

>>30 that's pretty cool, but offtopic. we should have a w3m thread somewhere.

32 Name: #!/usr/bin/anonymous : 2007-10-14 23:36 ID:oOCO0nIW

So, but really though, in light of sites like

http://www.xulplanet.com/references/objref/
http://developer.mozilla.org/en/docs/JavaScript
http://www.crockford.com/javascript/
http://www.quirksmode.com/

does anyone really think what >>1 said, about real information being hard to find, still holds? If so, I wanna know what's missing.

33 Name: #!/usr/bin/anonymous : 2007-10-22 03:08 ID:xCTcV1GB

There's some pretty good reading at http://eloquentjavascript.net/ too.

34 Name: #!/usr/bin/anonymous : 2008-01-16 01:16 ID:ZXwGXbcM

35 Name: #!/usr/bin/anonymous : 2008-01-17 01:38 ID:Heaven

Not unless someone implements it in JScript...

36 Name: #!/usr/bin/anonymous : 2008-01-17 06:06 ID:Pygmh3eQ

>>6

This is when you get the .pdf version of the book! Speaking of Javascript..... laugh

I really don't want to get into the whole Adobe/.pdf debate though, so I will just say that I use .pdf a whole lot and actually enjoy it and have accepted that not a lot of people agree with me! :'(

37 Name: #!/usr/bin/anonymous : 2008-02-11 08:58 ID:YshbvTdZ

Who uses firefox?
1) 12 y. o. or 60 y. o. unix geeks, screw them.
2) retards, screw them.
3) faggots who hate america and microsoft, definitely screw them.
tl;dr make ie-only sites with javascript and activex.

38 Name: #!/usr/bin/anonymous : 2008-02-11 16:44 ID:Heaven

>>37
My girlfriend uses firefox.
Screw her?

39 Name: #!/usr/bin/anonymous : 2008-02-11 21:25 ID:Heaven

>>38 If you don't mind.

40 Name: #!/usr/bin/anonymous : 2008-02-12 12:45 ID:Heaven

>>38
I thought you'd never ask!

Name: Link:
Leave these fields empty (spam trap):
More options...
Verification: