7 ms·
Saying "it's not the most elegant language" is quite (mis)leading. While I would not claim that it is the most elegant language, I would most definitely claim
by coreyp_1 10y ago
Saying "it's not the most elegant language" is quite (mis)leading. While I would not claim that it is the most elegant language, I would most definitely claim that it is elegant.
Two things that many people get wrong about JavaScript: (1.) Most of the ugly parts involve interacting with the DOM, and the DOM is NOT JavaScript, and (2.) Just because some people write ugly code with it does not mean that the language itself is ugly.
ES6 and ES7 have done wonders for the language syntax, and the flexibility of the language allows you to write in any combination of procedural, functional, prototypical, object-oriented programming styles. I mix them together as needed to make programs more intuitive and easier to follow. Programming is an art, and JavaScript is a powerful and versatile tool.
You are also wrong in that it being the only language supported by browsers. That may be the case now, but in the past many, many, many websites used flash and java applets. Quite frankly, the reason that JavaScript is what we have now is because it really is that good that it replaced all the other options.
All of the other questions are all over the board... It sounds like you are trying to get us to write a homework assignment for you.
- sAbakumoff 10y ago>>Most of the ugly parts involve interacting with the DOM, and the DOM is NOT JavaScript, and Yeah, like dealing with "this" keyword or type coercion in JS is not the ugliest thing ever in the history of Programming languages
- api 10y agoTry C++ template metaprogramming or Java collections before generics.
- mschuetz 10y ago> Yeah, like dealing with "this" keyword or type coercion in JS is not the ugliest thing ever in the history of Programming languages Try python. Python's handling of this/self makes javasacript look like the most amazing thing ever.
- krzyk 10y agoWhat do you mean? Could you give an example? I always regarded python self to be one of the cleanest ways to show that we have another parameter in a method.
- _ZeD_ 10y agoare you joking, right? in javascript you cannot ever KNOW what this refers to (is the instance of a new Thing()? is null? is "window"? is something set with .bind()? is just "the left thing before the dot before the function"? is something else?
- Sohcahtoa82 10y agoDoes "this" work differently in JS as it does from Python or even C++? Is it not always the object that owns the function currently being executed? If the "this" is implicit, then how can you possibly know where the variable comes from?
- tastyham 10y agoEh. Python and JavaScript are very similar at the language level. They each have warts and are more expressive in certain areas, but at a high level they have the same semantics and the exact same advantages and disadvantages.
- scriptkiddy 10y agoCould you please explain? It's always very clear in Python what `self` refers to. Self is always an instance of the parent object of a method. Some classes can also have static class methods that can be called from the class itself instead of one of it's instances. Maybe that is where your confusion is arising?
- StavrosK 10y agoClass methods don't accept a "self" argument, though. In those cases, you call it cls.
- cdelsolar 10y agouse ES6, Babel, and ===
- sAbakumoff 10y agoES6's arrow function might help to avoid "this" problem in some scenarios, but it does make it any better. Type coercion is a lot more than == vs ===.
- BinaryIdiot 10y ago> Yeah, like dealing with "this" keyword This can get a little confusing until you understand how context works. Then it makes sense but you know what? You don't always need to use this. In fact you can build entire applications in different ways without ever using this. And no writing without using this doesn't make your code ugly or unmanageable. There are just many ways to get the same or similar things done in JavaScript. > type coercion in JS Type coercion is ugly in any programming language. It's best to avoid it, even in JavaScript (which you can do, btw).
- giomasce 10y agoThe problem with type coercion is when it happens without you noticing it. You cannot "avoid" it...
- BinaryIdiot 10y agoSure but this problem is inherent to any dynamic language. I find other issues far worse than simple type coercion. What about calling a function? Most dynamic languages will let you pass in any number of parameters regardless of its definition and you may not even notice. You can avoid type coercion if you understand how the language works (aka strict equality in JavaScript) but this isn't something only in JavaScript land either.
- dozzie 10y ago> Most dynamic languages will let you pass in any number of parameters regardless of its definition and you may not even notice. Python will throw an error. Ruby will throw an error. Tcl will throw an error. Erlang will throw an error. I believe most of the Lisps will throw an error. What was it about "most dynamic languages"?
- BinaryIdiot 10y ago> What was it about "most dynamic languages"? I should have changed my text to not say "regardless of definition" because you can do that in Python, Ruby, PHP, JavaScript, etc. Python and Ruby support it through (star)args or default parameters JavaScript supports it regardless PHP supports it regardless We can argue semantics or the fact that some of those types of errors can be caught with some subset of dynamic languages but I don't think that's useful. My only point was when comparing a dynamic language with a static language I find variable function parameters to be one of the bigger issues over type coercion. But that's just, like, my opinion.
- z3t4 10y agothis is only used with the new keyword. You can however program JS avoiding both new, prototype and this, by using "factory functions". Or avoid OOP structures altogether using a more functional paradigm.
- sAbakumoff 10y ago>>this is only used with the new keyword This so not true. "this" is much wider paradigm in JS.
- z3t4 10y agoIf the new keyword is not used, "this" will point to the global scope. You do not however have to use the new keyword when creating the built in JS objects. {} is new Object(); If you find "this" confusing you can and should avoid using it. JavaScript has many bad parts that some programmers love to use because it makes their code "elegant". It is however possible to write simple and easy to understand code by only using the good parts.
- sAbakumoff 10y ago>>If the new keyword is not used, "this" will point to the global scope This is entirely incorrect information, consider a simple example: function f(){console.log(this.a);} var o={a:"c"} f.call(o) there is no "new" keyword involved, and "this" is not pointing to the global scope and there is a huge amount of other samples which I can show, but I won't. I don't have any problems with understanding "this" in JS. I just firmly believe that this is superb ugly stuff.
- z3t4 10y agoThat is indeed ugly stuff. Thankfully you never have to use f.call(o)
- sAbakumoff 10y agoI bet you never developed anything realistic with JS! The close neighbor of "call" called "apply" is a widely used tool.
- js-fiend 10y agoI haven't looked at ES6/7, and its true that any language in the wrong hands can be ugly. But there's a lot wrong with JS besides how it interfaces with the DOM[1]. Which is funny because it was originally conceived as a browser scripting language[2]. And JS beating flash and java applets may be more a result of market forces (Apple) and the lack of better alternatives. Brendan Eich designed JS in 10 days for the early era of the web, which is very different today. Its both a testament to the language and the hacks on top of it that its stayed in use this long. But maybe its time to move on? [1] https://medium.com/javascript-non-grata/javascript-is-a-dysfunctional-programming-language-a1f4866e186f https://medium.com/javascript-non-grata/javascript-is-a-dysf... [2] https://en.wikipedia.org/wiki/JavaScript#Beginnings_at_Netscape https://en.wikipedia.org/wiki/JavaScript#Beginnings_at_Netsc...
- graphememes 10y agoWhy do you believe the language is dysfunctional?
- smonff 10y ago3) Maybe a language don't need to be that "elegant", it's not required in all situations. I think I would prefer a "practical" language over "elegance" but like the appearance.
- tobyhinloopen 10y ago[] + [] === "" Elegant... hmmmmm
- ng12 10y ago[1,2,3].toString() === "1,2,3" [].toString() === "" It's only confusing to people who really don't know anything about the language.
- js-fiend 10y agothis might be a better example https://twitter.com/codinghorror/status/476826733576847360 https://twitter.com/codinghorror/status/476826733576847360
- graphememes 10y agoAre you arguing that this is confusing to you and therefore not elegant, or are you arguing that this code compiles and that means it is not elegant? Would you write that in production?
- tigershark 10y agoJavaScript is as elegant as a cat scratching his nails on a blackboard. it's a mongrel language without any whatsoever elegance. Taking your art metaphor further is like comparing the ceiling of the "cappella sistina" to a cut in a canvas.