-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CS2 Discussion: Question: New Feature Ideas #4913
Comments
From @carlsmith on July 28, 2016 20:57 ExtensibilitySome combination of macros, compiler options and AST transformers would allow users to define their own dialects without having to create a fork. We have a community of language designers, and have let that become a force that fractures our work into tons of abandoned projects, each adding one or two features in isolation. Having a community of hardcore, programming language enthusiasts should be a positive thing. Using a parser generator will make our compiler more difficult to extend. A handwritten parser can be extended more easily. A dialect should be distributable as a compiler configuration, which would typically be a few KB of JSON. A lot of the new features people want are parsed identically to existing features. Prefix, infix and suffix operators are more or less generic. You just need to define the spelling, the precedence and what it compiles to. We can also generalise constructs like keyword-predicate-block, where again, you only need define a spelling for the keyword, the precedence of the expression as a whole, and what it compiles to. The predicate is a generic expression, so that will parse automatically, and the same is true for any block, so it's actually just a matter of defining what the header compiles to. We could probably just map new operators and other constructs to invocations, passing any operands, predicates and blocks along as lambdas, so the user only needs to provide a spelling, a precedence and a runtime function that can handle the call. I've explored actually implementing this, and it isn't that complicated. The only issue is wanting to change so many other things in the process, you end up with a totally new language :\ |
From @carlsmith on July 28, 2016 21:20 Pythonic ForI explained the logic behind this at some length in coffeescript6/discuss#11, but to summarise again here: If we allowed unpacking a sequence inside a for-loop when the names we're assigning are wrapped in brackets (
|
From @carlsmith on July 28, 2016 21:23 Named FunctionsThe grammars There is a proposal to add the same logic to ES6, so this feature may just magically start working in CoffeeScript soon! |
From @carlsmith on July 28, 2016 21:23 Object and Set ComprehensionsWe don't have these, and they're awesome. It's one of my favourite Python features that CoffeeScript lacks. |
From @carlsmith on July 28, 2016 21:23 Proper Equality OperatorAn operator that tests the equality of arrays, objects and sets, based on their contents, like every other scripting language has, so expressions like |
From @carlsmith on July 28, 2016 21:23 Falsey Empty CollectionsEmpty arrays, objects and sets should be falsey when used as a predicate. |
From @carlsmith on July 28, 2016 21:24 Operator OverloadingIt's a really useful feature, especially for library authors. |
From @carlsmith on July 28, 2016 21:24 Automatically Reference First ArgsThe first argument to any function should be assigned to a reserved name. Other dialects have used employees.forEach -> console.log it.name, "makes", it.salary I'd rather assign the arguments array to |
From @objectkit on August 4, 2016 4:20 Method OverloadingWould be great if method overloading was introduced, at least in the context of classes.
Just hypothetical code here - but in this scenario, by providing a username and password to one method, a Credentials object could be created before being passed of to another implementation of the method. The Credentials object could be used in multiple ways - converting itself to JSON, validating username or password strings on instantiation... There are better use case scenarios. In terms of code output, the above classes login method could end up looking something like below in ES 4/5 pseudo code:
There are better ways to do this, but there will be overhead from method lookup, but acceptable I think. In production code with a fixed strict spec, it would be possible to eliminate the redundancy of method overloading if the need wasn't presented, resulting in code with more direct access to functions without lookup required... No idea if this would work for standalone functions, but don't see why not... |
From @objectkit on August 4, 2016 4:36 Enum
That would be somewhat similar to this in CS today:
Of course, hashes can be used instead
or
but in ES today, hashes involve implicit or explicit string comparisons.
and this is fine most of the time, but enums can also have methods, and are unique instance specific identifiers which cannot be reproduced anywhere else in code if not exposed. The example 'fun' implementation above would handle hashes or enums due to === checks used by switch statements, but enums would also allow for instanceof checks when appropriate, whereas string pollution (e.g. using strings instead of hashes) can scatter code in may cases. I haven't made a very strong case for enums here, but I do think they would be very useful in CS! |
From @objectkit on August 4, 2016 5:1 AdoptsWe can't really do interfaces in ES/CS. but we can do mixins. How about this?
That defines an EventListener. Some classes may extend from it. Others may just need to borrow its abilities by using it as a mixin. If we have a class that extends from another, there is no other choice but to use a mixin to aggregate its behaviour additionally, but if we introduced an 'adopts' keyword instead of 'implements', we could mixin multiple classes as well
The reason I'm suggesting an alternative to the word 'implements' is that interfaces are generally type level commitments and their implementations rarely include executable code (though that depends on the language you're using, and there are shifts there too), but the emulation of interfaces is not really where CS is! An alternative would be to reimplement CS extends, such that the first class passed to extends must be a class, but subsequent additions will be regarded as mixins
The key problems are
From my POV, the word choices are 'implements', 'adopts', 'adapts' or 'uses', most likely favouring 'uses' as its declarative in relation to the implementing class, not its inheritance chain. Its not a straightforward thing to define, but I think if we put some thought into it, we could come up with a viable solution. Anyone else? |
From @objectkit on August 4, 2016 5:44 Tuples
Just for example. Not proposing syntax. However, AFAIK, tuple like behaviour can be implemented in ES using Arrays and index transformations, so as a target language, ES can support them once CS transpiles.
I believe destructuring assignments can emulate, but I have to admit, I've failed to see how in exactly the same way? I'm sure tuple emulation must be possible in CS as is... would like some feedback on that! |
From @kirly-af on August 6, 2016 17:20 NaN is NaN
This way |
From @kirly-af on August 6, 2016 18:2 Generalized LoopsI talk about it in coffeescript6/discuss#11, but I would like to see generalized loops in CS that would handle Objects, Arrays, Strings and ES6 Iterables the exact same way. For backward compatibility, we could introduce a The syntax would look like: Examples: (console.log key, val) foreach key, val in {'foo': 'bar'}
(console.log idx, val) foreach idx, val in ['foo', 'bar']
(console.log idx, char) foreach idx, char in 'foobar'
(console.log count, item) foreach count, item in someIterrableObject |
From @rattrayalex on September 9, 2016 15:46 Closing this thread as we have decided not to add any non-EcmaScript features. |
From @rattrayalex on September 9, 2016 15:46 Though, I will point out that @carlsmith 's shalt project may be interesting to those wishing to experiment. |
From @rattrayalex on September 9, 2016 15:48 ... and should also mention that I am beginning work on a new language called LightScript, which may incorporate some of the suggestions on this thread (and from this repo generally). |
From @mrmowgli on September 10, 2016 4:12 I know his is closed but I realized how awesome it would be to have a transpiler to other languages besides Javascript, including Java byte code and self contained binaries ;) But that's just me loving coffeescript so much. Give a man a hammer and everything starts looking like a nail... |
From @GeoffreyBooth on September 10, 2016 23:34 A few years ago I had to do some coding in PHP, and I stumbled across https://github.com/btwael/mammouth:
If only all languages had such things 😄 |
From @rattrayalex on July 28, 2016 17:12
What new features would you love to see added to CoffeeScript?
Let's list them here, ideally one-idea-per-post, and then open new threads for features that garner interest.
Copied from original issue: coffeescript6/discuss#16
The text was updated successfully, but these errors were encountered: