Comparing JVM alternatives to JavaScript
renato.athaydes.com
renato.athaydes.com
First of all, Parcel is a dead simple to use bundler that supports JSX, hot reloading, code splitting, and various file types (including TypeScript) out of the box: https://parceljs.org
Second, that React code is much longer than it needs to be, mostly due to formatting, but if you use function components and React "Hooks" it can be extremely short:
const Counter = () => {
const [count, setCount] = useState(0);
return (
<div>
<p>The current count is {count}</p>
<button onClick={() => setCount(count + 1)}>Increment</button>
<button onClick={() => setCount(count - 1)}>Decrement</button>
</div>
);
};
With the imports and call to "render" it's about 15 lines of code, which is much shorter than all of his other examples.The class version (written how I'd do it) is about 25 lines, which still shorter. Here it is without JSX, using Preact's HyperScript-style `h` instead of `React.createElement`:
class Counter extends Component {
constructor(props) {
super(props);
this.state = {
count: props.count || 0
};
}
increment() {
const { count } = this.state;
this.setState({ count: count + 1 });
}
decrement() {
const { count } = this.state;
this.setState({ count: count + 1 });
}
render() {
const { count } = this.state;
return h("div",
h("p", "The current count is " + count),
h("button", { onClick: () => this.increment() }, "Increment"),
h("button", { onClick: () => this.decrement() }, "Decrement")
);
}
}
And of course these are toy applications, which aren't even representative of real applications. I'm not sure I can go back to imperative UI toolkits like GWT, etc.The application size seems approximately accurate, but if you really care about bundle size you could use Preact (which supports most of React's features). The brings the bundle size down to about 10KB, which is also much smaller than his examples.
Load time is also unfair due to lack of bundling.
Undoubtedly there exist better combinations of tools, but as someone just starting front end exploration, knowing what is the right combination is virtually impossible.
Even if you make it to the create-react-app page, the official documentation doesn't make a recommendation among three separate build options (npx, npm, yarn) and two app start options (npm start or yarn start). Worse, there's no explanation of why one would choose one method over another.
My experience with React is this type of muddled guidance is very common throughout the ecosystem.
https://github.com/facebook/create-react-app#quick-overview
EDIT: For reference, the URL where I see the ambiguous startup steps: https://www.google.com/search?client=firefox-b-1-d&q=create-...
- "To create a new app, you may choose one of the following methods:" (then suggests npx, npm, or yarn)
- "npm start or yarn start
Runs the app in development mode."
- Even from right below the anchor you linked:
"(npx comes with npm 5.2+ and higher, see instructions for older npm versions)"
This is in reference to the overview commands of
npx create-react-app my-app cd my-app npm start
which add to the ambiguity further down the page...Should I use npm or npx? Can I mix them? The quick overview uses both.
This is all confusing to newbies. I have no idea why they don't pick one way to do things (or at least explain why one might choose one vs the other).
To me it seems obvious that you use npx unless you're stuck with an older npm version, or you're already using yarn.
Why couldn't they just write that you should use npx if you have it? Or, since it works using npm too, why not just tell everyone to use npm?
There are so many non-obvious things here.
Why do we run some binaries via npm and others via npx? If you're going to use npm to run all the commands after create-react-app, why include npx in the document at all?
If you use npx to create an app per the directions, why does the animated output tell you to use yarn to start it (and not npm as in the text immediately above)? Why does the animation then ignore the output and use npm to start it?
The answers to these types of questions may be known to someone immersed in the ecosystem, but the presentation on the official page is definitely muddled and makes the answers far from obvious.
Those are best practices if your goal is to stick with javascript no matter what, which is not the goal of the comparison. Resorting to a transpiler which adds whole new complexity dimensions and failure points to your build, and doing so while aiming to introduce a complex workflow that requires half a dozen modules to become manageable is far from the ideal solution.
What? The entire post was about comparing JavaScript to alternatives which use... compilers/transpilers:
GWT - Java-source-to-JS, server and client-side framework
TeaVM - Java-bytecode-to-JS compiler
JSweet - Java-source-to-JS (and TypeScript) compiler with library ecosystem
CheerpJ - Full JVM implementation on the browser
Vaadin Flow - Java-source-to-JS-source, server and client-side framework
Bck2Brwsr - Java-bytecode-to-JS compiler http://cljs.github.io/api/cljs.spec.alpha/I can't remember the last time I had a type error, or maybe if I did it was so trivial to fix that it's not sticking out. Type errors wouldn't even rate in the top ten categories of bugs that I make or encounter, so it seems odd to pick a programming language with that as a primary concern.
All else being equal, it does seem nice at some theoretical level to have a compiler that checks type correctness, but there's lots of other issues that would also be nice to have the compiler handle, which it often doesn't. For example, TypeScript seems to (like JavaScript, so far) not have any bigints, which seems to me a much worse flaw than lacking a type checker. What good is it for the computer to check my usage of types, if it can't even do arithmetic correctly with them?
But maybe this is just more of that nice feeling. I can't recall the last time I overflowed a fixint, either. (64 bits help with that -- or even 53 bits.) It's admittedly not a major practical concern in my daily programming life.
Maybe there are people who fret about type safety the way I fret about overflow. I assume it must be a concern among some styles of programming, because I keep hearing about how languages without compile-time type checkers are bad, even though my experience does not agree.
(Then people go and use languages where the type system is merely at the level of "Number" and "String", and it lets you pass a loop index to a function expecting a height in centimeters, and that's considered acceptably type-safe.)
Super simple, super modern and easy to use. You will love it and forget those hyped madness what others do...
Additionally, Ember.js devs get the highest salary in frontend world. ;)
IIRC react requires nearly 300MB worth of npm packages just to get the hello world example to run. How does Ember fare in comparison?
Clojurescript truly is alien technology. Modern react has basically adopted Reagent's programming style with Hooks. Clojurescript/Reagent were 5 years ahead of the curve, truly amazing.
Clojurescript gives you a live repl, immutable data by default, core.async, macros, and an amazing consistent core library. None of these things are ever going to come to the javascript world
I'm 1000% sold on Clojure (and have done some production back-end tools with it), but every time I try to do front end or mobile, I struggle without outdated guides or books and relative lack of other current online resources to get me reasonably down the road toward success.
Apparently people who successfully use these tools are happily working and not having the time to educate new people. Of course it's not their responsibility, but it does seem that the Clojure community is far less involved in nurturing new users than many other languages/toolkits/frameworks.
Full-stack setup with Boot and hot reloading on both front and backend, with some basic SASS, DB, and configuration setup as well.
Have a look; even if it's not for you, it might give you some idea how to set up an application and dev environment.
deps.edn, shadow clj, and regeant seems like what I would try and target at the moment unless trying to do full stack datoms
In which case Fulcro looks like the future there just very complicated to learn I think I need to learn graphql first to help my understanding
http://www.luminusweb.net/docs/clojurescript.html
You can create a new project with Clojure/Script support by adding different flags. For example, for a re-frame project:
lein new luminus myapp +re-frame
This will generate the needed boilerplate and configuration. You can now start the server by running: lein run
The server will start a nREPL that you can connect the editor to on port `7000`, this is defined in the `my-dev-config.edn` file. The typical workflow is to connect to the REPL, and run your code as you're writing it.Next, you start ClojureScript compiler in a separate terminal with:
lein figwheel
The front-end workflow typically involves having figwheel running while you write the code, and it will automatically push changes to the browser. You can also connect to the nREPL started by Figwheel from the editor. This port is specified in `project.clj` under `:figwheel` with the `:nrepl-port` key. The default is `7002`. Once you connect the editor you run `(cljs)` function to switch to the ClojureScript REPL. You can now evaluate any code that's running in the browser. Note that Figwheel has to be started, and the page loaded in the browser first.The project is set up to keep all the code in the same repository, and you have three separate source paths:
* `clj` - server-side code * `cljc` - code shared between the server and the client * `cljs` - client-side code
Packaging the app is done by running
lein uberjarOf course, I don't much like Java, so that's not where I'm likely to go, but I am struck with what the author demonstrated here regarding that as an option. Like the author, I'm very curious about something like Elm; if I'm going somewhere with a type system, I'd like to go further along the spectrum of benefits types can provide.
And I'm also not sure we've reached the apex of possibilities of working more directly with HTML/CSS/JS, but that's highly domain/application dependent and another topic.
Normally everything more or less works with my fallback chrome in its default configuration, but then I feel we are more or less back to "optimized for ie6" days.
The Javascript that used to be produced was enormous, and of course on a per-service basis, and it had a big overhead on the parsing and running stakes. If any of you was using the console maybe 5 or so years ago, you'll know what I mean about the console loading experience (it was fine once the javascript got processed).
The GWT team at Google went on to write the j2cl compiler, and based on Github commit history, they're still working on it:
https://github.com/kotlin/kotlinx.html
... is an abomination.I love node 'cause it "just works" (but really it does). The app I work on is node TypeScript Nest.js backend and TypeScript Angular frontend. The set up process for a new dev is install node (takes like 10 seconds), clone the repo, npm install, npm start. Ready to start developing.
TypeScript is as simple as installing typescript, and running tsc from the command line. With ts-node you can simply make your npm start script "ts-node ./index.ts" and you're off and running.
Do you mean simple, or easy? I think the latter. The JS tooling seems well optimized for the novice user, but I think it's hard to argue that it isn't complicated behind that friendly face.
Also, I think most things seem easy once you know what you're doing. Almost tautologically so.
Aka "code that someone other than you can understand"
It's absurd to say JS was designed primarily as a functional language when there is mutation everywhere, inconsistent use of equivalence, and one of the looser type systems still in existence.
Either way, I'm surprised that that's been your experience, because I have found it to be the opposite. I've found TS to be most of what I like about C#'s typing (interfaces are an incredible, foundational tool) with much less of the ceremony. I still prefer C#, but I find TypeScript's flavor of OOP to be one of the lightest (in terms of enterprise-OOP, langs like Smalltalk obviously still take the overall cake).
Lets compare Java and Angular 6 (using your example)
Java Build system: Maven, javac Java module system: Class files
Typescript Angular Project: (as of Angular 6): Typescript compiler, Angular compiler, Babel, Webpack, Npm/yarn (which are not always interchangeable). Now if you have a complicated CSS setup you might have to run multiple CSS post processors. If you are using webpack they might be css-loader and sass.
Module system: CommonJS, AMD, UMD, ES6.
Javascript isn't difficult - it is needlessly difficult.
I bet it would take most front end developers over a day to set up all the dependencies for a "modern ES6 react-redux project" from scratch. That is why templates like "create-react-app" are popular- there is way too much plugin configuration and boilerplate necessary to get the toolchain working.
Both Clojurescript and Elm have much saner development workflows on the front end for example. (Both have their own compilers and a better package ecosystem)
Responding to someone complaining, "The tooling for X is too complex, there's too much of it" by saying, "Here's the answer -- another tool," is maybe just a little bit silly.
I won't say that JavaScript is amazing (I don't like it myself), but even reading the name Maven brings me back painful memories.
It skips the JVM altogether and complies Scala to Javascript. I haven't used it for anything significant, but I've heard nothing but good things.
Slinky React (https://slinky.dev)
JSON RPC (https://github.com/shogowada/scala-json-rpc)
Diode (https://github.com/suzaku-io/diode)
Scalably Typed (https://github.com/oyvindberg/ScalablyTyped)
Being able to use almost every React library but with full types and code completion is amazing. And with JSON RPC you can treat Client -> Server as though it's just another method call.
I wonder if we’ll do a loop with JSON and end up back at XML
Http://brython.info Http://pypyjs.org
No idea what the performance is going to look like for webasm, but might be a worthwhile sacrifice if the developer productivity gains were good enough (using the same language for FE and BE makes many things easier).
https://hacks.mozilla.org/2019/04/pyodide-bringing-the-scien...