C
Chris Angelico
Random rant and not very on-topic. Feel free to hit Delete and move on.
I've just spent a day coding in Javascript, and wishing browsers
supported Python instead (or as well). All I needed to do was take two
dates (as strings), figure out the difference in days, add that many
days to both dates, and put the results back into DOM Input objects
(form entry fields). Pretty simple, right? Javascript has a Date
class, it should be fine. But no. First, the date object can't be
outputted as a formatted string. The only way to output a date is "Feb
21 2011". So I have to get the three components (oh and the month is
0-11, not 1-12) and emit those. And Javascript doesn't have a simple
format function that would force the numbers to come out with leading
zeroes, so I don't bother with that.
What if I want to accept any delimiter in the date - slash, hyphen, or
dot? Can I just do a simple translate, turn all slashes and dots into
hyphens? Nope. Have to go regular expression if you want to change
more than the first instance of something. There's no nice string
parse function (like sscanf with "%d-%d-%d"), so I hope every browser
out there has a fast regex engine. When all you have is a half-ton
sledgehammer, everything looks like a really REALLY flat nail...
Plus, Javascript debugging is annoyingly difficult if you don't have
tools handy. I need third-party tools to do anything other than code
blind? Thanks.
Oh, and "int i" is illegal in Javascript. Whoops. That one is my fault, though.
Javascript's greatest strength is that it exists in everyone's
browser. That is simultaneously it's worst failing, because it becomes
nigh impossible to improve it. If Chrome's V8 starts supporting new
features and everyone else's JS engines don't, we can't use those
features. Even if they're added to the standard, there'll still be old
browsers that don't support things. The only way to add to the
language is to dump stuff into a .js file and include it everywhere.
But if anyone feels like writing an incompatible browser, please can
you add Python scripting?
Chris Angelico
I've just spent a day coding in Javascript, and wishing browsers
supported Python instead (or as well). All I needed to do was take two
dates (as strings), figure out the difference in days, add that many
days to both dates, and put the results back into DOM Input objects
(form entry fields). Pretty simple, right? Javascript has a Date
class, it should be fine. But no. First, the date object can't be
outputted as a formatted string. The only way to output a date is "Feb
21 2011". So I have to get the three components (oh and the month is
0-11, not 1-12) and emit those. And Javascript doesn't have a simple
format function that would force the numbers to come out with leading
zeroes, so I don't bother with that.
What if I want to accept any delimiter in the date - slash, hyphen, or
dot? Can I just do a simple translate, turn all slashes and dots into
hyphens? Nope. Have to go regular expression if you want to change
more than the first instance of something. There's no nice string
parse function (like sscanf with "%d-%d-%d"), so I hope every browser
out there has a fast regex engine. When all you have is a half-ton
sledgehammer, everything looks like a really REALLY flat nail...
Plus, Javascript debugging is annoyingly difficult if you don't have
tools handy. I need third-party tools to do anything other than code
blind? Thanks.
Oh, and "int i" is illegal in Javascript. Whoops. That one is my fault, though.
Javascript's greatest strength is that it exists in everyone's
browser. That is simultaneously it's worst failing, because it becomes
nigh impossible to improve it. If Chrome's V8 starts supporting new
features and everyone else's JS engines don't, we can't use those
features. Even if they're added to the standard, there'll still be old
browsers that don't support things. The only way to add to the
language is to dump stuff into a .js file and include it everywhere.
But if anyone feels like writing an incompatible browser, please can
you add Python scripting?
Chris Angelico