×

Welcome to the Slashdot Beta site -- learn more here. Use the link in the footer or click here to return to the Classic version of Slashdot.

Thank you!

Before you choose to head back to the Classic look of the site, we'd appreciate it if you share your thoughts on the Beta; your feedback is what drives our ongoing development.

Beta is different and we value you taking the time to try it out. Please take a look at the changes we've made in Beta and  learn more about it. Thanks for reading, and for making the site better!

Ask Slashdot: Making JavaScript Tolerable For a Dyed-in-the-Wool C/C++/Java Guy?

Soulskill posted more than 2 years ago | from the it's-an-acquired-taste dept.

Java 575

DocDyson writes "I'm a dyed-in-the-wool C/C++/Java developer with over 20 years of experience. I'm making a good living and having fun doing back-end Java work right now, but I strongly believe in being a generalist, so I'm finally trying to learn the HTML5/CSS3/JavaScript future of the Web. However, I find JavaScript's weak typing and dynamic nature difficult to adapt to because I'm so used to strongly-typed, compiled languages with lots of compile-time error-checking and help from the IDE. Does anyone out there who has made this transition have any tips in terms of the best tools and libraries to use to make JavaScript more palatable to us old-school developers?"

cancel ×
This is a preview of your comment

No Comment Title Entered

Anonymous Coward 1 minute ago

No Comment Entered

575 comments

Going down in flames (5, Insightful)

Anonymous Coward | more than 2 years ago | (#38961915)

Probably gonna get flamed for this, but my advice.. don't fight it! When in Rome.. etc.

Javascript isn't meant to be done like c++ or Java, so don't try! Think about the mess you get when an assembly guy tries his hand at Java. It's the same deal. It's a whole different mindset, and if you fight it you'll just end up with a big mess and a lot of wasted time.

That said, some stuff does transfer over. You can still go through proper requirements, design and testing. Basic principles like encapsulation and reuse still sorta apply (and are highly recommended imo). Before doing anything that seems like a common use case, check to see if someone has already done it (but don't blindly use it.. a lot of really shitty stuff out there.. but some gems too!).

Re:Going down in flames (-1)

Anonymous Coward | more than 2 years ago | (#38962107)

Anyone in here like playing with the skin on their nutsack? It's a habit for me.

I just keep grabbing some of the skin, putting another piece of skin next to it, and squeezing them together. The result is so interesting! Oh, my!

Re:Going down in flames (-1, Offtopic)

Anonymous Coward | more than 2 years ago | (#38962417)

Yeah, I like playing with the skin on your nutsack.

Drink (-1)

Anonymous Coward | more than 2 years ago | (#38961941)

Drink lots of booze.

Re:Drink (-1)

Anonymous Coward | more than 2 years ago | (#38962055)

Drink lots of booze.

What's the difference between nigger pussy and a bowling ball?
If you had to, I mean really HAD TO ... you could eat the bowling ball.

Re:Drink (0, Offtopic)

Anonymous Coward | more than 2 years ago | (#38962079)

My preference is vodka and lime...

Lime cancels out the harshness of the vodka, vodka cancels out the sourness of the lime, and the alcohol dulls the soul crushing pain of javascript.

Use good stuff for the first glass or two (grey goose is my preference).. then use the shitty stuff for the rest of the evening if you are cheap (polar ice is great for this!).

A language that compiles to JS (4, Informative)

wisnoskij (1206448) | more than 2 years ago | (#38961963)

You could try a language that compiles to JS/etc.
My friend uses HaXe for all of his server development (http://haxe.org/doc/why).

Re:A language that compiles to JS (3, Informative)

tomk (20364) | more than 2 years ago | (#38962085)

Unfortunately this is a great way to have to learn two languages (HaXe and Javascript) instead of one. I believe browser support for "source-level" operations (debugging, profiling, etc) for compile-to-JS languages will come some day, but that day is not today.

Re:A language that compiles to JS (1)

wisnoskij (1206448) | more than 2 years ago | (#38962335)

Oh I would not say that at all.
And even if you did, it still takes care of all of that annoying cross browser compatibility, OO, and other hard parts of JS.

Re:A language that compiles to JS (5, Informative)

mihajul (1650525) | more than 2 years ago | (#38962097)

On the topic of languages that complile to JS, GWT [google.com] is very nice, especially if you're using a Java back-end.

Re:A language that compiles to JS (2)

Ken_g6 (775014) | more than 2 years ago | (#38962261)

Indeed, this sounds like it makes a lot of sense. I recalled a Python to JavaScript compiler ("Pyjamas"), googled for it, and found an entire GitHub page of links to such compilers [github.com]. It includes compilers for Python, Ruby, C#, C, and more. Heck, there's even one for Perl!

The only problem is I haven't tried any of these, so I have no idea how good they are. On the other hand, I have used some pretty bad language converters. (Many of which I wrote on the spot, but still...)

Re:A language that compiles to JS (1)

wisnoskij (1206448) | more than 2 years ago | (#38962383)

Well HaXe in particular is designed from the ground up to compile to other languages.
I think because of this it has a lot of benefits over a simple converter.
I personally have never used it, but have both seen and heard about it a lot, and it looks so amazing for web dev.

framework (0)

Anonymous Coward | more than 2 years ago | (#38961965)

try playing with javascriptmvc

Javascript: The good parts (5, Informative)

mhh91 (1784516) | more than 2 years ago | (#38961979)

I suggest reading this book, it's gotten a lot of good reviews, I've seen a lot of people recommend it to people starting out with JS.

It explains a subset of Javascript that's simple to use, and also the most used in practice.

As a Javascript developer... (5, Funny)

RyuuzakiTetsuya (195424) | more than 2 years ago | (#38961985)

My advice?

Scotch.

Lots and lots and lots of scotch.

Preferably something that burns horribly on the way down and leaves you with a miserable hang over. Only because you've got to look forward to something that hurts less than JS development at the end of the day.

Re:As a Javascript developer... (0)

Anonymous Coward | more than 2 years ago | (#38962081)

As a C++ developer falling head-long into the javascript (and Flash... argh) world... this. This and THIS. Drink enough to the point where you can't distinguish the two and code away. The problems Submitter is having are ingrained in the language, you mostly just have to adapt.

Re:As a Javascript developer... (4, Informative)

RyuuzakiTetsuya (195424) | more than 2 years ago | (#38962161)

A serious answer is to not feel bad about using a framework like jQuery. It helps to know what jQuery's doing on the inside first and foremost.

Re:As a Javascript developer... (1)

confused one (671304) | more than 2 years ago | (#38962135)

This. Drink enough that you can't think and don't care anymore. I prefer Jack Daniels to Scotch.

While We're Talking About Irrelevant Bullshit (-1)

Anonymous Coward | more than 2 years ago | (#38962285)

This. Drink enough that you can't think and don't care anymore. I prefer Jack Daniels to Scotch.

I prefer yo mama to my hand.

Re:As a Javascript developer... (1)

gnapster (1401889) | more than 2 years ago | (#38962143)

Should I aim for a 0.135% blood alcohol content, or will I need more when first starting out?

Re:As a Javascript developer... (1)

Anonymous Coward | more than 2 years ago | (#38962201)

.1337% [xkcd.com]

Re:As a Javascript developer... (0)

Anonymous Coward | more than 2 years ago | (#38962145)

I can relate to this! In fact, I'm drinking Irish Whiskey right now, straight up! :-) I recently got a great job at a major company in a smallish division that does mobile browsers, and all of their webapps are JS and HTML5 based. My background is C/C++/PLSQL/Java/Dibol, etc. Our infrastructure is mostly Java, C++, and Javascript. Fortunately, I don't have to write a lot of JS code, and I don't have to write the JS webapps, just make them go as fast as possible - my job is performance engineering. In any case, I am reverse-engineering our code into UML models, and my head is about to explode! Hence, the Bushmills... :-)

As for Java, I still think it is C++ on training wheels. The fact that there is no multiple inheritance, except for interfaces, means that a lot of important classes are WAY overly big and complex, and do stuff they should not have to deal with, violating one of my major principals, locality of reference - keep the implementation close to the definition.

Re:As a Javascript developer... (1)

Assmasher (456699) | more than 2 years ago | (#38962159)

Amen brother... And keep the Scotch cheap. No use wasting the good stuff - you'll be bathing in it before long.

Re:As a Javascript developer... (1)

Mashiki (184564) | more than 2 years ago | (#38962181)

I hear self-immolation works well too. And it does wonders at the end of the day when the boss comes up and wonders why your productivity is so low.

Re:As a Javascript developer... (0, Informative)

Anonymous Coward | more than 2 years ago | (#38962443)

Could you software guys stop with the hyperbole? You're sitting at a desk pounding away at a keyboard. Some people have real jobs that hurt.

Not an Old-School Problem (3, Interesting)

RonBurk (543988) | more than 2 years ago | (#38961987)

Most "old school" programmers have some interpreted language in their toolkit. People who think "old" means 40 probably have Python/Perl/etc. People who are really old probably had Basic/Awk/etc. So, nothing to do with how long you've been programming, more to do with how narrow your background is. As with learning any new language, there's no getting around the basic advice of: Write More Code.

Re:Not an Old-School Problem (1)

Anonymous Coward | more than 2 years ago | (#38962391)

I was a mostly self-taught Delphi programmer with about 10 years under my belt (not much I'll admit) who learnt a bit of HTML in high school, when I started with PHP/MySQL+HTML4.01/5,CSS2.1/CSS3,JS using the book "MySQL and PHP for Dummies".

I'm now at a point where most of my questions are answered by either w3schools or php.net, but the the dummies book is a handy gentle intro. Also goes a little into setting up your server and security/hardening, which is as important as any feature of your app.

All languages have their pros and cons. I've never yet come across any reason not to learn a new one... even Visual Basic has its uses

Good luck

~ crutchy

Dart? (4, Informative)

supersat (639745) | more than 2 years ago | (#38961991)

Have you tried Dart? It's like JavaScript but with optional typing, and it compiles down to JavaScript.

Re:Dart? (2)

Timmmm (636430) | more than 2 years ago | (#38962259)

I've looked at Dart. It seems like javascript but with all the "hey, that's actually fairly neat" features removed, and their stupid counterfeight-typing system added on. Yeah... counterfeight typing. You heard it here first. Looks and sounds like static typing, but it isn't.

They probably *wanted* it to be static typing but supporting compile-to-javascript meant it was easier for them just to say "sod it, let's make it dynamically typed and call them 'annotations'". That's the only sane explanation for the insanity I can come up with anyway.

I still don't see why they couldn't have come up with a proper mostly-language-agnostic bytecode for the web. Like what LLVM sounds like it should be (but isn't).

Re:Dart? (2)

supersat (639745) | more than 2 years ago | (#38962363)

There is a version of Native Client called PNaCl which runs LLVM bytecode, but it's not finished yet...

Re:Dart? (4, Funny)

Threni (635302) | more than 2 years ago | (#38962365)

Counterfeight? I certainly did hear it here first. Sounds a little like what the rest of us call counterfeit. You're using a strongly typoed language, right.

Re:Dart? (5, Funny)

Concerned Onlooker (473481) | more than 2 years ago | (#38962413)

"Have you tried Dart? It's like JavaScript but with optional typing, and it compiles down to JavaScript."

If the typing is optional how do you actually program it? Voice recognition?

Adapt or die (5, Insightful)

Telek (410366) | more than 2 years ago | (#38961995)

This depends - are you looking to learn the new coding methods to remain competitive in the workplace, or just for fun?

Honestly if you make a living doing this then you need to adapt. You need to get over your preconceptions and accept the changes to the way computing works. There are millions of programmers out there, if you want to stay employed you need to show that you're adaptable to the new technologies while applying all of the tried-and-true knowledge and experience from your past. It's hard enough to get a job when you're more than a decade out of school.

Trust me, I understand where you're coming from. I hate the inefficiencies of the languages these days. I dislike the general idea of doing anything other than a script in a scripted language. However my (perhaps anachronistic) viewpoints don't have many applicable places anymore. Unfortunately the tradeoff between RAD and proper coding often leans a little too far to the RAD side, necessitating the use of many types of languages and tools that you will undoubtedly not enjoy.

Not only will you be a lot more productive, but you'll be a lot more marketable if you just succumb to the "dark side" that is today's trend in programming languages.

Re:Adapt or die (1, Informative)

JoeMerchant (803320) | more than 2 years ago | (#38962289)

Not only will you be a lot more productive, but you'll be a lot more marketable if you just succumb to the "dark side" that is today's trend in programming languages.

I might disagree with the productive part, while agreeing with the marketable part. If you can talk the talk, "oh yeah, I did this project where we pasted Javascript between Ajax and Ruby modules for X and Y all accessing a common SQL server and it scaled up to 20 parallel servers before the funding ran out..." that's what gets you hired - pointy haired boss thinks he needs somebody who can "leverage the existing Ruby codebase and deliver an SQL backend for the new client," so, you said Ruby and SQL in there and sounded convincing while you said it, you're hired.

As for productive, we had a little Python vs. C++ vs. Excel Macro code-off last year, Excel was the nominal winner because the existing data was in Excel and the destination of the processed data was also Excel, so it had a pretty strong homefield advantage, but the Macro code was really specifically purposed and very inflexible, to the point of pushing back on the requirements a little. C++ on Qt and Python on WxWidgets were more or less neck and neck for ease of coding and flexibility of product, Qt of course has access to more platforms and runs faster if you're doing something big, but in its place Python-Wx is just as good if you know how to use it.

If the project requirements had grown to about 3x the complexity (this was a one day programming exercise), I'd say the Excel Macro would have imploded and started to be a serious maintenance problem, Python and C++ would have scaled better, and at maybe 10-20x the complexity, the Python would have gotten a little creaky too, not so much due to inherent flaws in the language but more because of how it is typically used. Of course, you can write horrible C++ code too, but it has been around long enough that most experienced C++ programmers recognize the bad stuff in C++ on sight and can regale you with tales of projects gone wrong because it was done that way.

If your idea of productive is whipping off 3 or 4 relatively independent projects a week, leaning heavily on existing script libraries and not giving a damn if what you are doing is efficient or not, sure, JavaScript is fine, and it has the home field advantage in HTML5. If you're building bigger systems that evolve and need a maintenance lifetime of 5+ years, there are better tools for that.

go assert yourself... (3, Informative)

TheCouchPotatoFamine (628797) | more than 2 years ago | (#38962001)

let go, my man... breath the untyped air.

Real tip: "use strict" at the top of your code and and write using assert() methods. A little more tedious, but your used to that, right? Being "dyed-in-the-wool" and all...

one word: JQuery (5, Informative)

thatisscary (1297483) | more than 2 years ago | (#38962007)

While it won't get you over the loosely typed nature of the language, it will make things a bit more manageable. You can write nice terse code which accomplishes oodles, as opposed to hand rolling everything. There is something nice to javascripting. I find it a nice respite. JQuery makes it beautiful.

Re:one word: JQuery (4, Informative)

coffeeyesplease (2338710) | more than 2 years ago | (#38962281)

Completely agree. My advice to you is learn JavaScript on it's own merits. Stop comparing it to C/C++/Java or whatever. heck, you might even have to stop thinking in objects and all that comes with OOP because sometimes it just doesn't apply. In my experience and for what I see with most of my programmers, is that no one really bothers to learn JavaScript. They just keep on doing whatever they're we're doing in C/C++/Java and then complain about how crappy everything is. A good starting point is this book http://eloquentjavascript.net/ [eloquentjavascript.net] it's free and it's a also refresher on computer science in general, download chrome or firefox (with firebug) to help you debug (c'os that's a frustrating task, at times) As someone mentioned already it's a completely different mindset. I personally have a hard time programming anything that is not strongly typed. Mainly because I'll go into it already thinking that I don't like it.But for someone who's been programming applications (some web, some not) for 13 years, JavaScript can help you achieve wonders. I find practically unavoidable when it comes to web applications and it has helped me achieve some UI stuff that I thought impossible just last year. (and yes, JQuery is a must)

Difficult to adapt to (1)

Kohath (38547) | more than 2 years ago | (#38962009)

Adapt to it anyway. Do it by trying harder. The language isn't going to adapt to you.

That's an antipattern (4, Informative)

slimjim8094 (941042) | more than 2 years ago | (#38962011)

I have no particular love of Javascript, but when I work in it, I write Javascript. When I use Python, I write Python, not Java. When I use C++, I write C++, not C.

It's hard. It's annoying. But the idea is that you write the language like a "native". If you're really a generalist, it's not such a big deal. Read plenty of good Javascript to learn the idioms common to the language, and go from there.

I could write for loops using counters and statements terminating with semicolons in Python. But I don't. I use iterators, list comprehensions, and so on. Because that's how Python code is written.

The way I see it, the goal of learning a new language is the same whether it's a programming language or a spoken language - to be able to do useful things with it, and ideally come off as a native speaker. Look at it as a matter of pride.

Re:That's an antipattern (1)

stevenfuzz (2510476) | more than 2 years ago | (#38962091)

I write PHP like Java or else I would have committed suicide years ago. I have showed PHP code at job interviews where they said "Wow, this actually reads a lot like Java, it's very clean". Sometimes I just don't get your particular viewpoint, not that I completely disagree with it. I honestly think some languages coding standards are awful (PHP), but the language is very useful.

Re:That's an antipattern (1)

slimjim8094 (941042) | more than 2 years ago | (#38962191)

PHP is an exception (isn't it always?) :P

More seriously, I can't figure out if PHP actually has a coding standard, in which case it's obviously preferable to use something more readable than less. It always seemed less like it was thought out and more like it grew organically as people started using it for more than forms and counters and things. But my knowledge of PHP is limited to "it's a scripting language, embed it with <?php ... ?>, basic imperative syntax, here's the docs". Thankfully, I don't do anything with PHP more than hack on stuff for personal use sometimes. Can anyone enlighten me? What does quality PHP code look like? I'd guess frameworks like CodeIgniter or CakePHP would be the place to look.

Re:That's an antipattern (1)

Beeftopia (1846720) | more than 2 years ago | (#38962477)

I have a background in C++. I could write PHP like a tentative teenager, write a line, see what it does, write another line, and soon have a working program serving web pages.

Or, I could apply classical code hygiene principles, define a few constants, limit my use of global variables, use objects with methods and properties, global functions,organize my code, think about what I want to do before I do it. There are many patterns one can implement in PHP. I recently implemented a singleton pattern because I wanted to call a query once, capture the data, instantiate the encapsulating object once, and be easily able to access that object's data through multiple other functions in the execution path without multiple database calls and multiple object instantiations.

You can be as tight or as sloppy with PHP as you wanna be. Not being strongly typed doesn't mean one is forced to write sloppy, buggy, opaque sh-t. I've seen the most abstruse, difficult-to-track down bugs in C++. Strongly typed doesn't automatically equal clean, solid, transparent code.

The quality of the end product is dependent, IMHO, on the code hygiene.

Re:That's an antipattern (1)

Daniel Dvorkin (106857) | more than 2 years ago | (#38962103)

This is fine advice for every programmer working in every programming language, and I really, really wish more people would follow it. I've noted that the people who say "it doesn't matter what language you use" are among the worst for trying to write code in every language that looks like it belongs in whatever language they learned first.

Re:That's an antipattern (1)

nomel (244635) | more than 2 years ago | (#38962243)

I don't understand this. How does the code look that much different? Besides some syntax differences, they're all almost *exactly* the same. Some languages force you to format your declarations and types differently, but a for loop is a for loop, an object is an object with procedures, variables, scope, and all of whatever features the language supports, doesn't support, or pretends to support. Unless it's something like Haskell or a language that encourages unreadable lambda functions, they all look basically the same to me. Sure, javascript has interesting ways of declaring functions and building objects, but you could still translate it, basically on the fly and at a glance, to any other common language.

When I write code, in whatever language, it not that drastically different. It's all as clean and straightforward as possible for the task. If you look at it, you'll say "yeah, that's ", but only from syntax and slight formatting.

Maybe programming since I was 10 just means I don't see the code anymore.

Re:That's an antipattern (3)

multipartmixed (163409) | more than 2 years ago | (#38962423)

If you've been programming long enough, you realize that programs have "shapes" and programming languages are really .. like, ah..spoken languages.

Most people think of callback-heavy library routines, reams upon nested reams of functions (encouraged by jQuery and ilk) when they think of the JS language. This language makes it particularly easy to write programs of certain shapes (spaghetti is a shape, right?). Just like it is probably easier to write an opera in Italian (or Klingon) than Russian, because the words flow into the form better.

But, when writing JS to do UNIXy things, the code starts to feel a lot C, because the shape is UNIXy and we strongly associate C with UNIX. Just like a Russian rock song still sounds like a rock song. It might sound a little wonky, but you would totally identify it as a rock song because of the form (shape).

Here's a snippet from some UNIXy JS I wrote a couple of years ago. Obviously, it's not for the browser, it's for a POSIX system -- and I think that makes my point:

/**
  * Determine whether two paths refer to the same storage (file or directory), either by
  * virtue of symbolic or hard links, such that modifying one would modify the other. In
  * the case where either some or all paths do not exist, we return false. If we are
  * unable to verify if the storage is the same (such as by having insufficient permissions),
  * an exception is thrown.
  *
  * @param pathA A file or directory name
  * @param pathB A file or directory name
  * @returns boolean
  */
 
exports.same = function same(pathA, pathB)
{
  var sb1 = new ffi.MutableStruct("struct stat");
  var sb2 = new ffi.MutableStruct("struct stat");
 
  if (stat(path, sb1) != 0)
    sb1 = false;
  else
  {
    if (stat(path, sb1) != 0)
      sb2 = false;
  }
 
  if (!sb1 || !sb2)
  {
    if (ffi.errno == ffi.dh.ENOENT)
      return false;
 
    throw new Error("Unable to compare '" + pathA + "' and '" + pathB + "'" + syserr());
  }
 
  if (typeof sb1.st_dev != "undefined")
    if (sb1.st_dev != sb2.st_dev)
      return false;
 
  if (typeof sb1.st_rdev != "undefined")
    if (sb1.st_rdev != sb2.st_rdev)
      return false;
 
  return sb1.st_ino == sb2.st_ino;
}

Here's an example (4, Insightful)

gr8_phk (621180) | more than 2 years ago | (#38962471)

How does the code look that much different? Besides some syntax differences, they're all almost *exactly* the same. Some languages force you to format your declarations and types differently, but a for loop is a for loop

for (x=0; x lessthan 10; x++) //sorry, can do lt in comment
{
square[x] = x*x;
}

That's a for loop, while this:

square = [x*x for x in range(10)]

is a list comprehension in Python.

You can write it like a for loop - and I did when I was first learning Python - but it sucks to do that. This is probably what the GP was alluding to. If you really know a language you don't want to read crap written by people who think they're all the same with different syntax. This of course is but a single small example.

Know the language, practice safe coding (2)

plopez (54068) | more than 2 years ago | (#38962015)

Know the language well, sometimes you *want* wierd things to happen. But know the limitations. Also practice safe and defensive coding. Use facilities you have to minimize side effects. Test early and test often. BTW, both C and C++ can really bite you. So I find it odd this question is being asked. These habits should already have been developed. I've been there so I know.

Re:Know the language, practice safe coding (3, Interesting)

nomel (244635) | more than 2 years ago | (#38962299)

I think he's basically asking for jslint, where you can catch errors many levels deep in your code at compile time, rather than waiting for the code to crash when it, eventually, gets run (in unit test or whatever).

Open Source Code (-1)

Anonymous Coward | more than 2 years ago | (#38962035)

Why bother learning Javascript? If all Javascript is visible to the browser, by its very nature, that means nothing proprietary can be written in it. So, why would you choose to learn and use a language that is only meant for "reinventing the wheel". There should be enough open source Javascript where you really don't need to use Javascript code too much for your client, and since there is no reason to have Javascript server-side (since all Javascript is meant to be single-threaded and unscalable). So, why bother if you already know C/C++/Java. If you only knew PHP and you wanted to earn more money, then it would make sense that you would care about Javascript, because it would be more difficult (a more desirable technology). When you compare that type of a low-tech background with C/C++/Java, there is much more opportunity when sticking with technology that exposes you to domain specific knowledge (avoiding any desire to keep "reinventing the wheel").

Re:Open Source Code (1)

stevenfuzz (2510476) | more than 2 years ago | (#38962111)

The day I trust others to write code better than me is the day my work becomes just good enough. There is not a lot of vertical mobility writing good enough code.

Re:Open Source Code (1)

Beeftopia (1846720) | more than 2 years ago | (#38962359)

Javascript is a powerful complement to PHP, databases and server-based functionality. To do AJAX for example, you have to create the XMLHttpRequest object - created in Javacript in the browser - to send data to the server. And the browser is a very powerful engine. It should be exploited. It can pick up some of the server processing. I hear what you're saying about your code being totally exposed, but you can always keep the proprietary stuff on the server and send down the HTML only in those cases.

Can't teach an old dog how to sit... (0)

Anonymous Coward | more than 2 years ago | (#38962039)

...so give up on it.

Douglas Crockford (0)

Anonymous Coward | more than 2 years ago | (#38962047)

Try search about Douglas Crockford, he has amazing talks at yui theater and developed tools like jslint and a debugger one.

I passionately hate javascript (0)

Anonymous Coward | more than 2 years ago | (#38962051)

I am also C++ guy and I really hate Javascript. It is not a language. It is a hack. Some programmer got drunk and designed it over the weekend just to make fun of his half-brained manager.
Javascript is a multiplatform piece of sh@#$.

Why? (4, Interesting)

LizardKing (5245) | more than 2 years ago | (#38962053)

Why bother making the transition? You're background sounds like mine - C, C++ then Java - and based on a few years of dealing wih Perl I'd never willingly use a weakly typed language. Many errors in statically typed languages can be caught by the compiler, static analysis tools or nowadays by the IDE. Whereas with crap like Perl, JavaScript or *spit* PHP, such tools are hindered by the language and often by the libraries to the point where you'll drown in warnings that may or not be of genuine concern. In short, your existing skills are in demand, so leave the crap languages to the script kids.

Well.. (1, Insightful)

stevenfuzz (2510476) | more than 2 years ago | (#38962057)

I'm a c++ / Java guy that has worked with dhtml for around 10 years. The answer is both simple and complicated. For the most part, as you have realized, JS is a very dumbed down Java like language. It is about as strict as PHP (not as forgiving), and you can easily get going in the wrong direction trying to do seemingly simple things (like, getting the value of a select box). For the most part you can fake OO and more or less port over best practices from it's stricter big brother. I more often than not attempt to take the same approaches for JS as I would Java (albeit, it is not always possible or correct in the ways you are used to). Obviously you are not going to be setting up abstract classes or casting complex integers, but the pragmatics of programming are non-the-less the same. In fact, as a simple scripting mechanism over the dom, you shouldn't have to do any complicated data structure work (this is what the back end if for). So, the simple answer is to keep it simple, the complex answer is to attempt to follow best practices and use as little javascript as possible to achieve the desired effect. Just be glad you are not learning this 5-10 years ago, you would be spending half your time testing between browsers and the other half making your JS code look hideous.

should get you started... (5, Insightful)

VoidEngineer (633446) | more than 2 years ago | (#38962071)

First, get thee Aptana for development.

Second, download thee jQuery. I would also recommend jQuery Mobile and jQuery.tools.

Third, dig around in jquery until you find qunit for unit testing.

Fourth, do a refresher on Lisp and functional languages. They say that javascript got it's fathers curly braces and it's mothers lexical scope. It may *look* like C/C++/Java, but under the hood is ActionScript ala Scheme ala Lisp. And it a very real difference which gets played out in copious usage of events and callback functions. As a refresher, the HTML5 paradigm is basically an MVC paradigm, where HTML is handling the Model, CSS is handling the View, and Javascript is handling all the controller functions. Phrased differently, the HTML is describing the What is displayed; CSS is describing How it should be displayed, and Javascript is describing When it should be displayed. And the When gets implemented as callbacks and events. And it just so happens that functional languages are ideally suited for that kind of work (ala lambda calculus, etc).

Lastly, if you're brave, check out Node.js.

GWT (1)

Anonymous Coward | more than 2 years ago | (#38962083)

Use GWT. It generates Javascript from Java.

Re:GWT (4, Informative)

JThaddeus (531998) | more than 2 years ago | (#38962279)

I second this. I've been using the Google Web Toolkit (GWT, http://code.google.com/webtoolkit/ [google.com]) for about 5 years now with good results. Write in Java, compile to Javascript, and let GWT handle the browser differences. The source is all there if you want to see how their Javascript works, and you can insert you're own Javascript code when and where you want it. Finally, the user's group has been an excellent source of advice.

Seriously, find something else to do... (3, Interesting)

Assmasher (456699) | more than 2 years ago | (#38962117)

JavaScript can do amazing things, but it's a total disaster if you're coming from a more traditionalist background.

Let me give you a taste of what's to come for you :).

Let's say you have an Applet/ActiveX Control/Plugin of some type that your company has built and needs to be scriptable from JS, and it must also be able to call into JS (JavaScript devs can register for events, notifications, console/logging messages, et cetera...)

You add a new feature to your Company's doohickey. Now you need to test it properly.

Your customer set requires that you need to test on OSX Snow Leopard, OSX Lion, Windows XP, Vista, Win 7, OpenSUSE, Redhat, and Ubuntu. On each of these operating systems you need to test on the most popular browsers, so you get jiggy with Safari, Firefox, Opera, IE7, IE8, IE9, Konquerer, et cetera... Then you, depending upon the plugin's architecture, need to test on both 32-bit and 64-bit versions of the plugin in each browser on each operating system.

That's not even getting started with Mobile, or JRE versions, or different deployment types, code signing, et cetera, ad nauseum, ad infinitum.

If you think you don't need to test like that, you're in for a rude awakening my friend... For example, this very testing led to our discovering that in Firefox, on Windows 7 rapid LiveConnect usage between an Applet and JavaScript is perfectly fine if the applet has focus, or another windows has focus, but causes total freezing of Firefox/Java Plugin IF THE FOCUS GOES TO ANOTHER ELEMENT ON THE SAME WEB PAGE. How's that for crazy sh**? :) LOL.

Anyhow.

Browser application development is a nightmare.

I would pay good money for them to rip JavaScript out and everyone get together (yeah, I know, pipe dream) and come up with a client side scripting language that rocked oldSk00l.

GWT for the win (0)

Anonymous Coward | more than 2 years ago | (#38962155)

Write in Java, compile to JavaScript using GWT.

JavaScript "features" (weak typing, undeclared variables, ...) cause only bugs.

Lear perl (1)

TheInternetGuy (2006682) | more than 2 years ago | (#38962167)

My advice is;

Learn perl, learn to love perl.
After this any programming language will seem tolerable to you.

In fact, you may consider them as yet another of the many possible ways to do it.

GWT (3, Informative)

alannon (54117) | more than 2 years ago | (#38962175)

I think GWT is actually a reasonable tool for writing code that compiles to Javascript. This makes a lot of sense if you're writing your server code in Java, since your server and client code can all live within the same source tree and be edited with the same IDE in the same language. Significantly, this also allows you to debug your code using your Java debugger (read up on 'hosted mode' if you want to understand that witchcraft) while it's running in your browser. GWT also de-fangs the javascript event model that often leads to memory leaks. It might be of benefit to some people that by default (you can turn it off) the emitted JS code is heavily obfuscated. GWT is mature and well-supported, and integrates simply with vanilla JS code if you wish to.
Available for GWT is GWTQuery, which is (you've probably guessed) a jQuery clone for GWT, including events, effects, etc...

Google has tools for you (1)

Anonymous Coward | more than 2 years ago | (#38962185)

You can write in a type-ified version of javascript with a 'compiler' which statically checks your types and creates a minified javascript 'binary' for you to serve:

http://code.google.com/closure/compiler/
http://www.amazon.com/Closure-Definitive-Guide-Michael-Bolin/dp/1449381871

Or you can use GWT, and write java which compiles to javascript:

http://code.google.com/webtoolkit/

Or if you want to be on the cutting edge you can try DART, which is a whole new language, which compiles to javascript.

http://www.dartlang.org/

My tip (3, Insightful)

bonch (38532) | more than 2 years ago | (#38962193)

My tip is to never let yourself remain attached to a particular subset of languages for 20 years. Absorb all crazy things, because it makes you better in all languages.

Try LISP sometime.

Don't bother (0)

Anonymous Coward | more than 2 years ago | (#38962195)

There are many tool kits like jQuery which have zillions of plug-ins that already do most of the bread and butter functionality you'll ever need. There's little point in cutting javascript yourself for most things, not unless you're a professional in the language and need to.

Dynamic typing is paradise. As is static typing. (4, Insightful)

Qbertino (265505) | more than 2 years ago | (#38962199)

I'm just going the other way. Building my first app in C++ using Qt. Which basically goes like this: OMG you piped a literal string without it being a genuine QString into my label ... KERNEL PANIC! CRASH! 10 bazillion compiler errors. ... WTF?
Of course this sucks. However I'm well seasoned enough to know that when building a non-trivial application, it's exactly this sort of thing that will save my sanity in the long run.

With dynamically typed languages it's the exact opposite. Try building an IDE in JS. It has been done, but it need a solid amount of thorough planning and the one or other hack/stunt. However, writing a little script in JS is like having awesome sex compared to doing the same 'three-liner' in C++ which is like masturbating with a cheese grater in comparison. And still uses 30 lines.

All I can say is go with the flow. Wrap your head around dyn typing if you are not used to thinking in it and eventually you'll see the beauty in JS which blows C++ out of the water in the areas it is meant for.

Keep up with the spirit and good luck. ... And now excuse me, I have to set up my little QWidget 20-something lines of code with 20 typecasts strewn about just to get the bloody label to show a simple literal when I click a menu entry.

My 2 cents.

Use Google's 'Closure Compiler' (3, Informative)

arthur5005 (608816) | more than 2 years ago | (#38962213)

http://code.google.com/closure/compiler/ [google.com] It's exactly what you're looking for. It does type checking, it checks syntax and variable reference, it does file dependancy, and has a great inheritance system so you can get back to your Java/C++ ways. It's just awesome.

Be dynamic when you use a dynamic language (2)

steveha (103154) | more than 2 years ago | (#38962223)

Dynamic languages have different strengths and weaknesses than static languages. The best advice I can give you is: deal with it.

Best practice in a dynamic language includes automated unit tests for your code, for example. I don't use JavaScript so I can't tell you all the best practices and developer idioms for JavaScript, but I have heard that the best book is the O'Reilly reference book [oreilly.com] and that anything by Crockford [crockford.com] is worth reading.

Note that lots of other Slashdotters are already giving you very similar advice to what I wrote.

P.S. Hmm, doing a Google search for "JavaScript best practices" found this: http://www.javascripttoolbox.com/bestpractices/ [javascripttoolbox.com]

steveha

Re:Be dynamic when you use a dynamic language (1)

Anonymous Coward | more than 2 years ago | (#38962381)

Ah, unit tests... twice the code, twice the time vs a statically typed language. I love getting paid by the hour... thanks web :-)

I thank you for y0ur time (-1)

Anonymous Coward | more than 2 years ago | (#38962225)

uncover a story of the accounting Morning. Now I hav@e distributions slings are limited, OpenBSD, as the the wind aapeared = 1400 NetBSD are there? Let's a popular 'news fact came into Are you GAY Wash off hands clearly become Smith only serve The system clean I ever did. It Of the GNAA I Raadt's stubborn your spare time Forwards we must brilliant plan

JS is not OO (1)

bunhed (208100) | more than 2 years ago | (#38962229)

Javascript is not perfect but more importantly, it's not OOP. Forget OOP, see it for what it actually is and it turns into a pretty decent little languange actually. If you are a C++/Java head that is hard to do but just the act of seeing code as prototypes, without the OO paradigm, is a worthy exercise. You gain a cool way to view problems and it changes the way you code OOP to boot. ++ imho.

Re:JS is not OO (4, Informative)

BitterOak (537666) | more than 2 years ago | (#38962331)

Javascript is not perfect but more importantly, it's not OOP.

Actually, Javascript is object oriented. It's just that, unlike most object oriented languages, it is prototype based [wikipedia.org] rather than class based. [wikipedia.org] Both are legitimate forms of object oriented programming, although class-based is more popular now.

Get Over Yourself (5, Funny)

cthlptlk (210435) | more than 2 years ago | (#38962233)

Nan-in, a Japanese master during the Meiji era (1868-1912), received a university professor who came to inquire about Zen.

Nan-in served tea. He poured his visitor's cup full, and then kept on pouring.

The professor watched the overflow until he no longer could restrain himself. "It is overfull. No more will go in!"

"Like this cup," Nan-in said, "you are full of your own opinions and speculations. How can I show you Zen unless you first empty your cup?"

Have Fun With It (2)

Bob9113 (14996) | more than 2 years ago | (#38962235)

You're right, Javascript is a way different style of coding than C/C++/Java, but that's OK. So is Lisp. Surely you wouldn't feel wounded by having to learn Lisp. Use the different style to develop a new facet to your perspective on programming. Duck typing is pretty well respected in academic OOP, so it's not like you're going to be learning GOTO statements or anything.

Debugging is a bit harder, but that's OK, fire up Firefox, go to "Tools >> Web Developer >> Web Console." That'll give you most of what you're looking for (use console.log("message") to write to the console). You can check out Firebug also, if you want something a bit heavier. I personally ditched Firebug as soon as Firefox's Web Console got good enough, because I found Firebug a bit too clunky, but lots of people swear by it.

Leave the preconceptions and stereotypes behind, check out Wikipedia on Duck Typing [wikipedia.org] and give it a go. Don't sweat it when you make noob mistakes -- you're supposed to do that when you're a noob to a language. Give it a crack, have fun with it, relax, it's really not a bad language once you get into it.

Perl (3, Interesting)

rrohbeck (944847) | more than 2 years ago | (#38962239)

Learn Perl first. Or maybe LISP. That way you'll get rid of the statically-typed mindset.
Java/ECMAscript is Perl/Python in C++/Java clothes. Don't even think about C++ or Java. It doesn't work that way. :)

It's a good time to look, but I wouldn't jump in (3, Informative)

fean (212516) | more than 2 years ago | (#38962251)

Take a look at Sencha / ExtJS... It's aimed squarely at enterprise-level developers/engineers, not the script-kiddies that rant and rave about the cool shit they can do because they've overwritten a 'built-in' type. It should work with Google Closure, as well...

IDEs are in terrible shape. There's WebStorm and Aptana... neither of which hold a candle to what you're used to, but it's better than notepad/textmate. I'm an linux/eclipse guy, but can't get used to the ways that Aptana breaks shit, so I tend to jump back and forth between WebStorm and SublimeText (it looks nice, but it's not 'all there').

There are some good books out there, JS: The Good Parts [amazon.com], Eloquent Javascript (free) [eloquentjavascript.net]... and I'm starting on Test-Driven Javascript Development [amazon.com], though I can't say if it's any good yet...

I'd recommend doing a little bit on the side, get your feet wet, but don't commit yet. Thinks have changed a lot in the last year or two, and nearly everyone and their dog is becoming an HTML5/JS Dev. You're behind the curve already, and will have a hard time getting ahead, so I'd wait until the editors and browser compatibility is better before diving in.... don't ignore it, and if you can find someone who will pay you to torture yourself, do it... but don't be too anxious.

Dynamic languages have static rules (2)

btherl (2263512) | more than 2 years ago | (#38962267)

Dynamic languages actually have strict, static rules behind them which implement their dynamic features. If you learn those rules then you may be in more familiar territory. Weak typing is really just a list of rules for automatic type conversion.

These steps broke the logjam for me (2)

Beeftopia (1846720) | more than 2 years ago | (#38962301)

I'm a C++ guy and here's how I got conversant with Javascript:

1) Get "Javascript: The Definitive Guide", by Flanagan, published by O'Reilly.

2) Read the chapters on Objects, Functions, Classes and Constructors.

3) Wrap your head around closures.

4) Understand the concept of function prototypes.

It's different than strongly typed languages. Just about everything is an "object" in Javascript. Including functions. Learn the subtle difference between defining and declaring a function - and it's nothing like what that means in C++.

Take from C++ the concept that you can have objects which have methods and properties. Then open your mind and read those chapters I mentioned. And don't try to apply any more C++/strongly-typed preconceptions. The "Definitive Guide" was not pleasure reading. It's not informal and humorous. It's dense. And it's geared towards those with some programming experience. But read those chapters and I think you'll be most effectively able to leverage your experience with strongly typed languages into Javascript.

I think Javascript is great and it is object oriented so you can get jiggy with it.

Also - give yourself an assignment with it and start hacking away.

Go with the flow, my man (5, Insightful)

multipartmixed (163409) | more than 2 years ago | (#38962303)

I have 20 years of C under my belt, 15 of those paid. I currently spend the vast majority of my time writing JS, and I love it.

Back in the good old days, we didn't pick C because of it's great syntax, or the warnings from the compilers (which have gotten much better in the last 20 years!). We picked it because it fast, portable (enough), available, and you could use it to do the stuff we were interested in.

Well, times have changed. JS and CPUs are now fast enough that execution time is not were "fast" usually matters: *developer* time is. JS syntax is good enough. Runtime warnings are getting good enough if you're writing ES5 strict code. Most importantly, if you're writing code for the web, you pretty much have to pick JavaScript. (Just like writing X11 code 15 years ago pretty much meant C++).

Syntax -- "go with the flow, my man". It's juicy, delicious. Don't be limited by the lack of types: embrace the flexibility. Prototypal inheritance is awesome in its simplicity, shallow object hierarchies make for easy reasoning. Make you *get* closures.

Functions are first-class members, like strings and arrays and objects. Sure, their literal syntax is longer than "", [] or {}, but function(){} is still a literal.

Just as the developer who thinks GNU make is some kind of super-shell is doomed to failure, so will the developer who thinks JS is a variation of something else.

JS isn't the new C. It's not the new Java. Or C++. Or Scheme. Or Perl. Or Python. Or Logo. Or BASIC. It's JS.

I currently write a LOT of day-to-day mundane code in JS. Some exciting code, too. I write web pages, validate forms, load modules (CommonJS), and design object exchange protocols and the applications which use them. That's on the web browser.

On the web server, I'm using it kinda like 1995's PERL. I query databases, do CGIs. I can call into POSIX. I write daemons, and "shell scripts". Some week I'll spend a few days and make my CGIs faster than CGIs. Remember mod_perl? Same deal. Mast fast_cgi. I dunno, performance metrics say I don't need to quite yet.

It's a hell of a language. But if you really want to work with it, you have to "get it". Be comfortable with it's multi-faceted layer. Understand that it's "functional", "object oriented", and "imperative", all at the same time.

In C, the Zen boils down to "everything is just a number". That's why string operations are so easy in C once you "get it". In C, the Zen boils down "everything is just a jsval". So, it's IS typed -- everything is the same variadic type. Get over writing reams of code to make your little soldiers walk the goose step, and just tell them where to go. They'll get there.

Go With The Flow or Vaadin (0)

Anonymous Coward | more than 2 years ago | (#38962347)

If you *really* want to learn the screwball, loosey-goosey mess that is Javascript/HTML/CSS, then you just need to dive it and embrace the chaos. If you just want to be able to write web apps while leveraging your back-end Java skills, then check out frameworks like Vaadin.

Javascript: The Good Parts (Douglas Crockford) (5, Informative)

oldspicepuresport (1551767) | more than 2 years ago | (#38962379)

This is book is worth every penny and more (~$18 on amazon).

Like the submitter, I come from C/C++/Java background and always despised Javascript whenever I had to deal with it. I picked up this book a few months ago and can confidently say that this book completely changed my view of Javascript. Javascript is a quirky language, and has some really bad parts (the book has a chapter dedicated to the bad parts). This book clearly explains common misconceptions about the language, as well as all the things a programmer used to a more traditional language needs to look out for. The book explains how Javascript works under the hood in great detail (the prototype-chain, functional scope, type conversion and equality, first class objects/functions ,closures, etc.)

This is a book for programmers, it's not a cookbook or how-to, and you need a good understanding of programming for it to be useful. That being said, for programmers coming from more traditional languages to Javascript, this book is exactly what you're looking for. I can honestly say that in a few short months Javascript has gone from one of my most hated languages to one of my favourites. The language is incredibly powerful and expressive once you get a good understanding of how it works and why.

Adapt and you might like it. (0)

Anonymous Coward | more than 2 years ago | (#38962403)

I'm an old timer like you. I made the jump about 2 years ago and I have to admit the jump was difficult at first because I kept trying to fight it. What! You don't know until you run you script and it doesn't work that you have a typo? How weird. Once you get over this you realize, hey, this is kind of cool, I can go into a web browser and it tells me what is wrong, much more so than the c/c++ compiler ever did.

My recommendations:

use http://www.w3schools.com/ as your go to website for reference.
Get used to both Chrome's development tools as well as Firebug in Firefox. You debugger is your browser tools, not an ide.
Learn jQuery, even if you think you don't need it you WILL use it if you get seriously into javascript.
There are several patterns that simulate data encapsulation, google it and read about them.
Closure is your friend. It is a very weird concept but once you use it you can't live without it because it allows encapsulation.
If you are curious how something is done on a website, right click on it select "Inspect Element" in chrome or FF, go to the script tab and look at the source, this was weird to me, hey all your source is available to look at. If the source is minimized ie9 will even unminimize it for you.
Your ide is nothing more than a text editor, not better than vi, notepad, you pick, though eclipse/Netbeans/DevStudio all give you things like code completion.

After my 2 years of working with javascript, I can honestly say it is kind of fun and maybe even rewarding...Do I miss the tough technical problems from C/C++, of course but you know what javascript gives you a whole new set of problems (my favorite is tracking down things where an if statement doesn't work because it is comparing a string instead of a number and doesn't tell you, so 3 == 3 will return false).

GWT (Google Web Toolkit) (1)

Anonymous Coward | more than 2 years ago | (#38962421)

GWT lets you write your front end in Java using widgets. It compiles your code to Javascript taking care of any variations needed to work on the different browsers.
You install the GWT plugin to your browser, and whamo, you can trace through your front end code in eclipse, without needing to redeploy changes to the server. Beautiful!
I replaced a JSF/Facelets/RichFaces/JavaScript/AJAX/HTML/XML/CSS implementation with GWT and saw a massive performance increase coupled with humongous decrease in complexity.
I honestly feel sorry for any poor sucker stuck in AJAX/JavaScript/CSS/HTML hell. Let Google take care of browser compatibility problems and get to use Java on both the front and back ends. What more do you want?

Old school != IDE (1)

Gothmolly (148874) | more than 2 years ago | (#38962469)

If you're an "old school developer" you use vi, in a telnet window. You don't get 'help' from an IDE.

Use Coding Standards, Libraries, and Good Books (2)

strimpster (1074645) | more than 2 years ago | (#38962497)

A language is not evil because it isn't strongly typed. Just because a language offers that option doesn't mean that you have to use it though. There are a lot of things that languages offer that aren't the best tool in all cases. This is where coding standards come in really helpful :)

That being said, I think that these could help you out:

  • JSLint - this is a linter that has some IDE support to help ensure that your code will adhere to some good standards
  • jQuery - this will help to abstract browser differences away so that you don't have to worry about that to cause your site to not work
  • QUnit - this is a test suite to aid in development
  • JSCoverage - helps to measure code coverage of unit tests.

JavaScript has been around for a long time and has lots of books and articles written. This is a huge benefit. I personally think that JavaScript Patterns by Stoyan Stefanov is a good quick read to show you how to implement popular design patterns in JavaScript. A deeper discussion can be found in his book Object-Oriented JavaScript.

jQuery (0)

Anonymous Coward | more than 2 years ago | (#38962511)

jQuery is the answer to everything.

Load More Comments
Slashdot Account

Need an Account?

Forgot your password?

Don't worry, we never post anything without your permission.

Submission Text Formatting Tips

We support a small subset of HTML, namely these tags:

  • b
  • i
  • p
  • br
  • a
  • ol
  • ul
  • li
  • dl
  • dt
  • dd
  • em
  • strong
  • tt
  • blockquote
  • div
  • quote
  • ecode

"ecode" can be used for code snippets, for example:

<ecode>    while(1) { do_something(); } </ecode>
Sign up for Slashdot Newsletters
Create a Slashdot Account

Loading...