3 ms·
True Javascript has maps, and you could use immutable.js for your structures. It also has functional capabilities too thesedays. But the difficult part of langu
by hacker_9 9y ago
True Javascript has maps, and you could use immutable.js for your structures. It also has functional capabilities too thesedays. But the difficult part of language design is actually making all these pieces work together fluidly. This is what Clojure achieves.
Immutable.js is great until I need to use a 3rd party lib that doesn't support the structures, so there is a copy involved and performance is lost and the code gets ugly. Functional constructs were botched into JS, so most code out there is a litter of imperative and functional, as well as containing lots of mutable global state. It's object orientated, losing much of the benefits that come from being functional first.
> I'm not sure what you mean by mutability introducing scaling problems
Side-effect free programming makes reasoning about your code easier. More here:
https://stackoverflow.com/questions/214714/mutable-vs-immutable-objects/214718 https://stackoverflow.com/questions/214714/mutable-vs-immuta...
> The only REPL I've used is Python's
I've not used it, but the point is you can change code and upload it as the programs runs. Great for tweaking stuff. And because there's no global mutable state, you don't have to restart the REPL very often as everything just works.
> JS doesn't actually compile
Actually it is compiled on page load. Also JS has no macros, but it does have some metaprogramming capabilities at runtime (reflection mainly). Again though, having a feature doesn't make it any good. Clojure's consistent and easy API blows JS out of the water.
- weberc2 9y ago> Immutable.js is great until I need to use a 3rd party lib that doesn't support the structures, so there is a copy involved and performance is lost and the code gets ugly. Don't use a library for immutability, just don't mutate. Easy-peasy. > Functional constructs were botched into JS, so most code out there is a litter of imperative and functional, as well as containing lots of mutable global state. It's object orientated, losing much of the benefits that come from being functional first. Yeah, multi-paradigm code is a pain. > Actually it is compiled on page load. Also JS has no macros If we're being pedantic, it compiles continually during interpretation as most popular implementations use JIT compilation. But my point is that macros wouldn't benefit such a language because there is no discrete compile phase. > it does have some metaprogramming capabilities at runtime (reflection mainly) I guess I'm not very familiar with metaprogramming. Most anything I can do with macros in a compiled language I could do at runtime in a dynamic language without special standard library or language support. I'll take you on your word that metaprogramming is useful and that Clojure does it better. Anyway, I don't think you answered one of my questions--how is Clojure's IDE support? Can it do gotodef or tell you about the types of parameters, etc?
- hacker_9 9y agoThe problem is JS is built from the ground up to be mutable. For example one big difference in Clojure is that all mutation is done through the Atom, which is transactional, making it threadsafe. I wasn't being pedantic saying JS is compiled, because it really is. Sure it's compiled to an IR though, which is then JIT compiled as needed. Nice thing about macros is they are zero cost abstractions, so there is no overhead added by using them. For example in C# using Linq creates garbage, so you can't use it in a game engine else you get freezes every couple of seconds as the GC does a collection. With macros you can have the convenience while still compiling to something that is memory efficient. As for an IDE, look at the Cursive plugin for IntelliJ. It's free for personal use and gives you a debugger, autocomplete, errors, goto definition, find usages etc.
- weberc2 9y agoThe following responses are terse because I'm posting from my phone. Apologies in advance! JS is not parallelized, so whether or not it's thread safe is a moot point. Python is also compiled to a bytecode before interpretation; were still don't call it a compiled language. In a JIT language, macros aren't significantly faster than runtime abstractions. In the latter case, you can always precompile your abstraction on program load at the expense of slower start times (think regex engines or precompile linq queries). The cost is negligible. I can't seem to find anything on type documentation for Cursive. How can I ask it what type a function returns or what types it's arguments should take?
- hacker_9 9y ago> JS is not parallelized https://johnresig.com/blog/web-workers/ https://johnresig.com/blog/web-workers/ https://ponyfoo.com/articles/understanding-javascript-async-await https://ponyfoo.com/articles/understanding-javascript-async-... > Python is also compiled to a bytecode before interpretation; were still don't call it a compiled language. https://softwareengineering.stackexchange.com/questions/24558/is-python-interpreted-or-compiled https://softwareengineering.stackexchange.com/questions/2455... > macros aren't significantly faster > you can always precompile your abstraction on program load at the expense of slower start times http://www.ilikebigbits.com/blog/2015/12/6/the-fastest-code-is-the-code-that-never-runs http://www.ilikebigbits.com/blog/2015/12/6/the-fastest-code-... > How can I ask it what type a function returns or what types it's arguments should take? http://www.braveclojure.com/core-functions-in-depth/ http://www.braveclojure.com/core-functions-in-depth/