5 ms·
Why is it ok that Javascript is the only client side option?
- bdfh42 16y agoYou are on a path to enlightenment. JavaScript is an elegant and truly flexible language - very well suited to the roll we have given it in remote (and until recently) pretty simplistic client environments. I suggest that your issues are not with JavaScript per se but with managing the flow of data and functionality between the server and the client. I am not suggesting that will become easy but, with experience, you will find workmanlike solutions.
- pedrocr 16y ago>You are on a path to enlightenment. It's starting with a bit of rage though :) > JavaScript is an elegant and truly flexible language To me it looks like it has a beautiful prototype-OO language trapped inside it somewhere. The point is more I'd rather get the work done with the tools I like than be forced to learn it. > very well suited to the roll we have given it in remote (and until recently) pretty simplistic client environments I find strange that what suits the environment is a language instead of a bytecode interpreter of some sort. Lua seems to have pretty compact implementations for example. > I suggest that your issues are not with JavaScript per se but with managing the flow of data and functionality between the server and the client. I am not suggesting that will become easy but, with experience, you will find workmanlike solutions. I have issues with that I know but what I always feel is that I am struggling with that plus figuring out how to properly iterate an array or implement a dictionary (both things I've found to be ugly and/or non-trivial in Javascript)
- bdfh42 16y agoPerhaps time for a little zen ;) >I'd rather get the work done with the tools I like Well you can - within your own computing environment but when you want to reach out and run code on your user's computer then you have to take the tools available. In this instance we have a (broadly) common language that runs on Windows, Mac, Linux and then some - thats pretty amazing. <language instead of a bytecode interpreter It would be trite to point out that what you have "under the hood" in JavaScript implementations is a pretty good JIT bytecode interpreter. JavaScript code represents a fully portable version of the code that will run in the user chosen browser on the user chosen hardware platform. <properly iterate an array Just picking on of your points here - It may be that you can solve each obstacle just the once and retain that solution into the future. As an example try https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/forEach https://developer.mozilla.org/en/JavaScript/Reference/Global... for how to add "forEach" functionality to an array - an array which (of course) can contain objects of any type. I just love the ability to work with arrays (collections) of objects representing server side classes.
- pedrocr 16y agoThanks for the reply >In this instance we have a (broadly) common language that runs on Windows, Mac, Linux and then some - thats pretty amazing. We have enough VM's that can do the same, it's not really a technical issue, which is what frustrates me. >It would be trite to point out that what you have "under the hood" in JavaScript implementations is a pretty good JIT bytecode interpreter. Yep, and I'd rather be able to target that. > JavaScript code represents a fully portable version of the code that will run in the user chosen browser on the user chosen hardware platform. It isn't fully portable really. Much less than any standardized bytecode anyway. One thing I've also struggled with is that I not only have to figure out Javascript I have to figure out each browser's take on it. I've had the same code fail subtly on Chrome while working fine on Firefox. > for how to add "forEach" functionality to an array I implemented this kind of thing in my own code and it works although the "block" syntax is a bit ugly ("function() {}"). > I just love the ability to work with arrays (collections) of objects representing server side classes. I'm not sure what you mean here. One bit that has frustrated me is replicating in Javascript code what I already have for the same concepts/models in Rails. Although some of that is surely bad separation between client and server on my part.
- bdfh42 16y agoYou are probably aware of these anyway but - just in case... jQuery (and other frameworks) deal with almost all browser compatibility issues when it comes to the UI. JSON is a great format for passing class properties from server to client and back again making it reasonably straightforward to connect (via AJAX) JavaScript objects with server side classes.
- tzs 16y agoI think the problem he's highlighting is with the browser executing a specific language. If it used a bytecode system, like JVM, CLR, or similar, you could still use Javascript--just compiled down to the appropriate bytecode. But others could use Ruby, or Python, or Java, or C#, or any other language that can be compiled to the appropriate bytecode.
- count 16y agoThey're not mutually exclusive. Coffeescript[1], for example, compiles to javascript, but isn't javascript itself. I'd bet most browsers have a JVM installed as well, so there's that... [1]http://jashkenas.github.com/coffee-script/ http://jashkenas.github.com/coffee-script/
- lelele 16y agoJavascript _is_ the bytecode system. Many people have laughed after Joel Spolski for Wasabi. Well, Joel had the right idea: just use whatever in-house language you want, just be careful to translate it in a language/platform your customers are more likely to have installed already,
- Roridge 16y agoWhy not just use GWT?
- pedrocr 16y agoBecause I'd probably still prefer to write Javascript than Java. But a GWT approach is one possible solution and there are some Ruby projects that do similar things. None are production ready though. For reference: http://hotruby.yukoba.jp/ http://hotruby.yukoba.jp/ - Implements the YARV (ruby 1.9) bytecode in Javascript (most promising one in my view) http://github.com/mneumann/rubyjs http://github.com/mneumann/rubyjs - Compiles a subset of Ruby code to Javascript
- Roridge 16y agoI happen to agree with you. My biggest issue with GWT is that it generates the Javascript, and I am at it's mercy. However sometimes it's important to get function over form?
- junklight 16y agoOh dear. First of all - shipping binary code to browsers. Please. No. Flash is bad enough. Say good bye to all the grease monkey style hacks and remixes and lots of other interesting things about the web. Secondly - either you are a programmer or not. I can't actually tell from your article if you want to be or not. However if you want to be a good programmer then you need to learn other languages - you might not be an expert in those other languages but being able to navigate your way round them - it is good for your programmers brain. Eric Raymonds famous article actually recommends you should try and learn a new language every year http://www.catb.org/esr/faqs/hacker-howto.html http://www.catb.org/esr/faqs/hacker-howto.html And thirdly - Javascript is actually a real cool language masquerading as a very dull mainstream one. I resisted doing too much in it for years but as I needed to do more and more I found out that its very powerful and flexible. Also if you use something like jquery you get a lot of Ruby style bits and pieces. And lastly - it might be a cliche but that doesn't mean its not true (to use another cliche in defence of the one I am about to use) - If all you have is a hammer then every thing looks like a nail. Ruby might be a pretty good language - but there is a reason there are so many other languages and its not because all the other people are idiots who weren't smart enough to come up with Ruby.
- pedrocr 16y ago>First of all - shipping binary code to browsers. Please. No. Flash is bad enough. Say good bye to all the grease monkey style hacks and remixes and lots of other interesting things about the web. Monkey patching bytecode may very well be harder but is that really used? Greasemonkey is marginal at best. What other things do you have in mind? >Secondly - either you are a programmer or not. I can't actually tell from your article if you want to be or not. However if you want to be a good programmer then you need to learn other languages - you might not be an expert in those other languages but being able to navigate your way round them - it is good for your programmers brain. I've learned plenty of languages and do appreciate some of the points of Javascript. I just don't see why everyone seems to defend it as the one-true-language for the client side. For everything else people make plenty of diverse choices yet somehow on the one platform that for historical reasons is stuck with a single language saying you'd rather use another implies somehow that you don't get it. >And thirdly - Javascript is actually a real cool language masquerading as a very dull mainstream one. I resisted doing too much in it for years but as I needed to do more and more I found out that its very powerful and flexible. Also if you use something like jquery you get a lot of Ruby style bits and pieces. I am using jQuery and it does have some goodies. The point isn't that with effort I couldn't make myself more comfortable with it. The point is that I don't see much that Javascript gives me that Ruby doesn't. So the fact I am forced to use Javascript is a net-negative for me. >If all you have is a hammer then every thing looks like a nail. Ruby might be a pretty good language - but there is a reason there are so many other languages and its not because all the other people are idiots who weren't smart enough to come up with Ruby. Certainly. And I do use other languages. The reason I'd like to be able to use Ruby for both codebases is that that would allow me to do interesting stuff I can't right now. In fact the same criticism can be made of Javascript, that because it's the only hammer available everything looks like a nail. I'm proposing more languages, not less.
- toretore 16y agoTL;DR: I don't actually understand how JavaScript works, but I thought writing a nonsense article demonstrating my willingness to bash it nonetheless with an aggressive headline and post it on HN myself would bring me some desperately needed attention.
- bdfh42 16y agoUnkind my friend. I think the OP is looking for encouragement and enlightenment. Perhaps you could share some thoughts on how you tackle these issues.
- toretore 16y agoThe OP deliberately wrote a rant about something he doesn't understand with an attention-grabbing headline and I called him out on it. I don't think that's unkind. I would have assumed good faith were it not for him explicitly stating he actually doesn't want to learn JavaScript but still wants to bash it.
- pedrocr 16y agoYou seem to be focusing of if I know Javascript or not. I don't know enough and I am learning. So it's not that I don't care. It's that I don't understand why Javascript being the only option on the client side is OK somehow. I've changed the title to be less aggressive.
- pedrocr 16y agoIf I do or do not know Javascript is actually tangential to my point. What I find strange is that the browser environment forces a language on developers and that is seen as OK. When apple was adding language/framework restrictions to the AppStore people were screaming bloody murder but somehow the browser status quo is fine. That being said the title was probably too agressive. The original was not very descriptive and it was what I came up with on the spot.
- nervechannel 16y ago
- BonoboBoner 16y agoI hated JS for years, but started to love it in the last couple of months. In my experience, as long as you're not prejudiced and dont judge JS for its flaws, it will treat you very well.
- nervechannel 16y agoActually, there used to be a choice. When I got into web dev, I got several gigs doing IE-specific sites in VBScript. Think how much worse it could have been if JS hadn't won.
- deleted 16y ago[deleted]
- RyanMcGreal 16y agoFor enlightenment, read Crockford's Javascript: The Good Parts.
- pedrocr 16y agoI have actually, that's the book I took with me. It made me understand the language more and just highlighted how it has an interesting model behind it (e.g., prototype and async) and a pretty bad syntax in front of it (e.g., constructor stuff).
- DjDarkman 16y agoNobody is stopping the Ruby devs from writing a Ruby interpreter for the browser. Here is the recipe: 1) invent a type that the browser current doesn't understand like: application/ruby-script 2) write a parser for it in JavaScript 3) Profit?? It would look like this: <script type="application/ruby-script"> //your browser will ignore this but your parser won't //sorry I don't do ruby to come up with an example </script> <script src="yourawsomerubyparser.js">