Bear Bibeault wrote:
Paul Clapham wrote:and you will find that 90% of JavaScript code is indeed crap.
Methinks the man is overly optimistic.
JavaScript is one of the most widely used languages on the planet, yet one that is misunderstood by the vast majority of people using it. Its abuse ratio is likely higher than most other languages. I feel bad for it at times.
Bear Bibeault wrote:Jeanne addressed your last point. Is JavaScript your first scripting language? Your first loosely typed language? Your first language outside of Java? The things that seem to be horrifying you are not unique to JavaScript, but are properties of most loosely-typed scripting languages.
Bear Bibeault wrote:
The goals of such languages are brevity and flexibility.
It'd take far too much time to justify each and every reason that scripting languages are as loosely constructed as they are, or to give examples of the benefits that they provide. That's what books are for. I don't know what books you are using, but I'd recommend Head First JavaScript, JavaScript: The Good Parts, and my own book Secrets of the JavaScript Ninja (written with John Resig and currently in early access prior to publishing) in that order.
To a use pop culture reference: "Let go, Luke." You need to let go of your preconceived notions to use the Force.
Mark Spritzler wrote:Steve, I have the same basic feelings as you. I am very big about doing things that makes it easy to understand the code and maintain it, and some of the things that can happen in JavaScript because of its "design" allows for some bad things.
That's why Eric told me to read "JavaScript the Good Parts" (Which I finished last night for the first read through. I need more than one read through). Because there is some great power in how Javascript is designed to help you write web applications, in which Javascript was built for. So as Bear says it is designed that way because it is best for what it is used for in web applications. I can imagine if Javascript was built like a statically typed language and like Java then things like closures, function callbacks, asynchronous code wouldn't be as simple as it is in JavaScript.
And most JavaScript programmers know to avoid creating global variables. You know it is also easy to create global variables in Java and it is just as bad an idea.
Basically, I have problems because I have to think differently and sometimes hack to get something to work like I want in JavaScript, where I don't have those issues in Java. And that JavaScript sometimes makes me write code that I cringe at because I would never ever want to do that same design in Java. But if I was using Pascal, which it type safe, I also would use a completely different design.
Mark
Jeanne Boyarsky wrote:Most of the things that horrify you are features of scripting languages in general. Search for weak typed and dynamic languages. Examples include Python and Ruby.
This isn't bad; just different. Scripting languages aren't rare or a one off. They are an important concept to understand. Also, learning different types of languages makes you a better programmer because you learn to think differently about problems.
And your reaction is inexperience. Don't let that bother you. Think of it is learning a new programming concept rather than being horrified. This also shows you want to be a software developer not just a "Java programmer". The former has flexibility.
Bear Bibeault wrote:Let me just say that if you approach JavaScript from the point of view that it is somehow "Java lite*" you will be very confused. It is its own language and all those properties that seem to violate your sensibilities make it a powerful and flexible language.
I'd highly recommend starting over without the perception that JavaScript has anything at all to do with any other language built for a completely different purpose. Keep an open mind and you might find that, for the purpose for which it is intended, JavaScript is an elegant and powerful language.
I'd also highly recommend that you should learn how to couch a discussion in reasonable terms rather than just bad-mouthing things you clearly do not understand. Your post comes across as rather unprofessional.
* Changing the name of the language from LiveScript to JavaScript back in the mid 1990's was a huge mistake as it gives people the idea that it's somehow related to Java. Except for a syntax influenced by C syntax, they have very little else in common.
Stephan van Hulst wrote:Submitting Callables to an ExecutorService seems perfect for this task.
Create a Callable class that returns an image from its call() method. You can then cancel and timeout the task through the Future class.
Here you can change the timeout between loading images in another thread (make timeout and timeunit volatile) and they will affect the next image being loaded. You should allow the user to cancel a task explicitly by providing a cancel button that calls currentTask.cancel().
Darryl Burke wrote:
Steve Stevenson wrote:Another surprising thing is that there doesn't seem to be a resize notification for containers; it only seems like the notification is available for components.
java.awt.Container extends java.awt.Component. Every Container is-a Component.