• CoffeeScript - a rather new and easy language
    23 replies, posted
Okay, a few months back a guy named [url=http://github.com/jashkenas]Jashkenas[/url] made the first steps towards something awesome that is now know as [url=http://jashkenas.github.com/coffee-script/]CoffeeScript[/url]. CoffeeScript is a programming language that compiles to JavaScript. This makes it somewhat web related, but this is mostly about the design of the language. So let's look at some syntax: [code]one: 1[/code] This was assignment. As you can see it is different from the "conventional" equality sign. The reason for this is that it's closer to how JSON looks/works. [code]square: (x) -> x * x[/code] Okay, the above is a function. As you can see there is no return statement or anything. The last "expression" is what will be returned. Let's look at something more awesome: [code]print "Okay" if 18 < age < 24[/code] What the above does is that it says: if 'age' is more than 18 and less than 24, then print "Okay". [code] printName: (name) -> print "Hello, $name" printName("Henrik")[/code] What will the above print? If you guessed "Hello, Henrik" then medals for you! As an extra trick you can also say: [code]printName "Henrik"[/code] And it will still work! ---- You've only seen the top of the iceberg. CoffeeScript got Object-Orientation (Classical), array slicing, comprehensions, function binding, pattern matching and many other cool things. I hope you like it :) Github Page: [url]http://github.com/jashkenas/coffee-script/[/url]
Seems to borrow a lot from Ruby, while hiding the bad parts of JavaScript. Also, the OO features are the same as JS, they're both prototype based (Not sure what you meant by "Classical").
[QUOTE=jA_cOp;21075183]Seems to borrow a lot from Ruby, while hiding the bad parts of JavaScript. Also, the OO features are the same as JS, they're both prototype based (Not sure what you meant by "Classical").[/QUOTE] Yes, it borrows a lot from Ruby and Python. [code]class Animal move: (meters) -> alert @name + " moved " + meters + "m." class Snake extends Animal constructor: (name) -> @name: name move: -> alert "Slithering..." super 5 class Horse extends Animal constructor: (name) -> @name: name move: -> alert "Galloping..." super 45 sam: new Snake "Sammy the Python" tom: new Horse "Tommy the Palomino" sam.move() tom.move()[/code] Stuff like that.
Looks nice
Oh, it does have class based object orientation, I looked around the website but couldn't see any of it.
I prefer the not fucked up syntax of most other languages.
Agree, that looks hard to follow if your used to something else.
Probably takes some getting used to, but looks good for quickly throwing stuff together not a huge fan of x:(y)-> for functions
I'd agree with that at-least. The part where it'd take some getting used to.
I think the function syntax is awesome, but then again I'm a huge fan of lambda expressions.
I can't see myself liking this too much. But then again, if it is simpler than javascript then I may learn it because I don't know javascript.
Perhaps it's theoretically easier to use, but the arbitrary syntax differences are annoying. One thing that I like about Ruby is that it has very elegant, simplified, unique syntax but you can still code stuff like C++ or Java if you feel like it, so you aren't forced to learn a new way of writing everything.
Why do you want familiarity? How will you ever find better solutions if you're allergic to new stuff?
Easy and therefor uncapable of doing complex stuff.
[QUOTE=jA_cOp;21182292]Why do you want familiarity? How will you ever find better solutions if you're allergic to new stuff?[/QUOTE] Familiarity is always good because you know certain things will work. And also, the more time you spend with a language the more proficient you'll become, so you may be able to see an error with a c program, but since you aren't too familiar with a CoffeeScript syntax, you probably would spot.
[QUOTE=Pepin;21195084]Familiarity is always good because you know certain things will work. And also, the more time you spend with a language the more proficient you'll become, so you may be able to see an error with a c program, but since you aren't too familiar with a CoffeeScript syntax, you probably would spot.[/QUOTE] In some cases this can be a problem: you write code that would seem logical for your old program language, because the syntax is similar, but because it's a different programming it doesn't work. You can be thinking in the wrong mode, essentially. As a little example, in C# you might do [code] SomeClass some_object = new SomeClass(); [/code] Whilst you'll get no end of errors trying to do it in C++. The closest working thing (in syntax) is [code] SomeClass* some_object = new SomeClass(); [/code] But what you probably want is [code] SomeClass some_object; [/code] I'm not sure how well, I've made the point I was trying to make, but hopefully you get the idea :) [b]Edit[/b] On Topic: Actually, as this compiles to javascript, it seems really quite cool, as I'm not a massive fan of javascript, really. Might have to have a poke at this.
[QUOTE=Pepin;21195084]Familiarity is always good because you know certain things will work.[/QUOTE] You'll know certain things will work after 5 minutes reading about the language, too. In most cases, or with this language almost every single case, the different syntax expresses the same underlying concepts you find in other programming languages. [QUOTE=Pepin;21195084]And also, the more time you spend with a language the more proficient you'll become, so you may be able to see an error with a c program, but since you aren't too familiar with a CoffeeScript syntax, you probably would spot.[/QUOTE] Language proficiency is a small part of programming. I see that you also mentioned syntax; have you ever attempted learning a second language? Learning the syntax is a tiny, tiny part of learning a new language, and if you haven't gotten the syntax down yet, spend 10 more minutes doing research before you go debug someone elses CoffeeScript.
[QUOTE=jA_cOp;21182292]Why do you want familiarity? How will you ever find better solutions if you're allergic to new stuff?[/QUOTE] [QUOTE=jA_cOp;21195696]Learning the syntax is a tiny, tiny part of learning a new language...[/QUOTE] I don't get it. What does familiarity have to do with "finding new solutions", especially if the syntax is as trivial as you make it sound?
[QUOTE=jA_cOp;21195696]Learning the syntax is a tiny, tiny part of learning a new language.[/QUOTE] Maybe it's just me, but it tends to be closer to half the work I do. 99% of the language features tend to be isomorphic (vars, arrays, classes); it's just the syntax to make them work that you have to learn.
[QUOTE=Ortzinator;21202316]I don't get it. What does familiarity have to do with "finding new solutions", especially if the syntax is as trivial as you make it sound?[/QUOTE] Pepin was the one who mentioned syntax. Understanding the syntax and understanding the actual underlying concept of something are completely different things. My point was, if you're scared away from new programming languages because it's unfamiliar, you'll never find new and interesting concepts (you might even come to like the different syntax, although it's mostly a subjective thing). And are you arguing that syntax isn't trivial? If so, in what way is it not a trivial thing? Say you come from JavaScript. You know that to do assignment, you do: [cpp] myVar = 123; [/cpp] You know what assignment is, and you know the syntax for it in JavaScript. Then there's functions. [cpp] myFunc = function(){ return "Hi!"; }; [/cpp] Pretty simple; assign myFunc to a new function. You've read that in CoffeeScript you make functions with -> and you assign with :, ergo: [cpp] myFunc: -> "Hi!" [/cpp] There is no explicit need for 'return' because (like in many functional languages, and also Ruby) the last expression in a function is returned.
As a little extra [cpp] myFunc: -> "Hi!" [/cpp] Compiles to: [cpp] (function(){ var myFunc; myFunc = function myFunc(){ return "Hi!"; }; })(); [/cpp] Note that the function is now named and it has been enclosed in a function to avoid polluting the global namespace ;) --- On this different-than-Algol-and-C-syntax-makes-it-confusing-debate. The point of CoffeeScript is to introduce a simpler and much more logical syntax to JavaScript. A colon is used for assignment because it is used for assignment in JSON, which is a subset of JavaScript. Since JavaScript is functional, functions are used in different ways compared to C, and therefore the need for a simple syntax.
[QUOTE=jA_cOp;21195696]Language proficiency is a small part of programming. I see that you also mentioned syntax; have you ever attempted learning a second language? Learning the syntax is a tiny, tiny part of learning a new language, and if you haven't gotten the syntax down yet, spend 10 more minutes doing research before you go debug someone elses CoffeeScript.[/QUOTE] It isn't learning about the differences in languages that mixes me up, it's more with getting them mixed up. I've been programming mostly in PHP, AS3, C, HTML/CSS and for me at least, I can confuse the languages a little bit. Usually small dumb mistakes that are easy to fix, but they are sometimes hard to spot depending on the compiler.
When this has a windows executeable, i might consider trying it, untill then..
Honestly? Javascript is ridiculously simple as it is, simplifying it any more is just overkill if even possible (how can you simply a hammer for example?). If that is even the intent of the language. Either way, the moment I saw it replaced the = operation with : I realized its just changing syntax to be different, not for any design reason. Cool project for him, pointless for all practical reasons.
Sorry, you need to Log In to post a reply to this thread.