by spricket · 7y ago · 0 comments
Java, C#, Rails, and to some extent Python are much saner choices. The massive churn of the JS ecosystem bleeds through to the backend, hard.
JS could use a little more of the cruft and process that makes Java and C# especially so "uninteresting".
Java especially is kind of a joy to work in if you ignore the cruft. Everything is generally well documented, the libraries are mostly very solid, code is almost always backwards compatible, there isn't a zillion ways to do everything, frameworks tend to live for a decade or so.
And it's faster than JS, and uses way less memory, and mostly solved dependency hell and bloat over a decade ago.
Java feels like it was designed, not grown. Everything follows similar convention so it's easy to pick up new libraries. The advantages are many. The drawbacks are few as long as you use things like Lombok and code generation liberally. By the way; code generation using agents, annotation processors, and bytecode manipulation is pretty much standard and a godsend for doing interesting things (and getting around the cruft) .
In java, I can write code on the fly at runtime, or even during compile time using standard tools. Js barely even supports reflection. This is a huge underrated shortcoming of js if you're doing anything complicated
Can you explain what Java offers with regard to reflection that JS doesn't?
My feeling is that reflection is almost moot in JS since you can inspect/mutate objects at runtime however you like. But maybe I'm missing the point of reflection.
There is a Reflect object with a bunch of static methods on it in ES6. It mostly just replicates functonality that already exists in the language, and my suspicion is that it's mainly there so it can be extended at a later date without breaking backwards compatiblity.
Among hundreds of other things, getting the return type of a method and getting the input parameter names (+ types) in a way that doesn't revolve around literally parsing the functions toString() representation.
Oh, and typeof checking that isn't disgustingly broken.
Type information literally doesn't exist at runtime, though. Isn't it kind of ridiculous to compare languages like that?
Correct if I'm wrong, not all types get erased in Java. Doesn't type erasure only happen for generics? Say I have a non generic, plain Java class and want to inspect one of it's method's return types at runtime to see if it returns class A or class B. I can do that, right?
Ah, that's quite cool.
Which in some ways is a good thing as you can do a lot more optimizations.
Maybe I'm just complaining that JS is too dynamic, but being able to generate code at compile time with reflection and know it will generally work (type checked) is nice.
Tip: in JS, I don't want OOP class. If you really want class, could you show me the intention behind it?
Adding another example, JPA MetaModel generator that allows you to make strongly typed calls in ORM.
Basically, it let's you generate code at compile time that's seamlessly integrated into the existing code. So it's generated code that still gives you IDE autocomplete support etc.
I automagically map some postgres JSONB columns to a parsed object form. Looks just like a regular typed nested object.
router.get('/users/:id', (id: UUID) => ...)
router.get('/products/:id', (id: Int) => ...) router.get('/users/:id'. skipNonUuid(id => ...))
You simply have a function/middleware that does the check.... or `compose(skipNonUuid, dbo.findUserById, ui.formatView('modelName'))`You can do function composition that is nearly as simple and far more flexible in general with JS
There's no way to hook into the loading of modules in a standard way - you have to know how the modules are compiled and required.
One thing comes to mind, how to twinkle stuff inside closures?
Though Java was 'designed', it was not 'designed' to be an http/web server.
JS, particularly Node.js has really adapted itself to that well.
And one small but massive difference: JSON is how data is passed and it fits seamlessly into Javascript, and doing JSON in Java is an ugly, ugly thing.
As soon as you compare not JS/Java, but Java/Tomcat vs. JS/NodeJS - then you get a different comparison.
I quite like using Typescript on Node.js over Java - development speed is faster, and this is a really important thing.
It is only a matter of browsers getting native support for gRPC.
With gPRC there's still a lot of binding code, and you need to map all of that in Java, but you do get some validation etc. out of it. It does make the 'data transfer' comparison a little less harsh.
https://en.wikipedia.org/wiki/Billion_laughs_attack
It got me thinking about it. JSON is annoyingly simple at times, yes. But that also protects it from some pretty gnarly stuff seen in XML and YAML. I suspect it's a considerable contributor as to why it's the choice transport format.
I wouldn't toss it in with XML just yet.
Why do you think so? Jackson and Gson work very well. Serialising and deserialising from/to POJO/JSON is trivial with them.
In Java, you have to abstract the document and write a lot of code to access, add, remove things etc. - or - because there is no such thing as an untyped POJO in java, you have to set up a ton of things if you want to use real objects.
You could also use a POJO for the fields you know and put a map inside for the fields you don't know.
If that's not enough you can use JsonNode, or ObjectNode where you can freely add and remove json values.
But yeah json is much nicer in JS generally
At least, that is how I find it, my productivity shoots up when I don't have to be moving between two imperative languages that most likely share a lot of their syntactical DNA with C but each have their own fun little differences.
I guess you could hire less proficient engineers which is a sell for startups, but I don't think it's worth the downsides of the current js ecosystem
I have mixed feelings about this. I don't feel comfortable with assuming that just because I use the same library in backend and frontend, I don't have to ensure consistency and behaviour. But then again, I've used this approach in one ClojureScript project (ClojureScript can transpile a lot of Clojure libraries to JS), and it is convenient.
And don't associate less proficient engineers with Javascript dude !
And that is only when not using JSF, Spring, Forms, MVC, Liferay, Sitecore, which generate the JavaScript validators automatically from type annotations anyway.
For my projects, the Web layer is only the View part of MVC.
Aside from form validation I find I might have a number of utility functions that are used on both layers.
I find there are a few other edge cases, but those are the most common situations where reuse is nice (on the other hand what I often do for personal projects is just build the server side and client side code from a gulp pipeline and not worry about needing 'isomorphic' code reuse, but often teams on paid for projects find this approach confusing)
[1] Whoever came up with isomorphic really liked their fancy math terms. Personally I'd have chosen automorphic, as it's all contained inside JS.
There is something precious to being able to do more with substantially less code, which is why I avoid OOP all together. You can't do that in Java.
Oh god...
Yeah, no. None of this stuff is a substitute for actual code quality. Give me a good engineer that refuses to write tests over a mediocre one that does TDD any day.
Compared to when I'd have to use ActionScript, JavaScript, VBScript, VB6, T-SQL daily... that was sometimes painful... then adding C# and VB.Net to the mix was ugly having to switch from one area of code to another.
Just choose the best programming language, and everyone can learn it; and they'll be happy and grateful in the long run that they chose to learn this new language, rather than use whatever they were familiar with.
Moreover, Java is such a simple and an easy language to pick up. If the cruft is too much to deal with, go with Kotlin. An experienced developer could learn either language (Java or Kotlin) easily over a single weekend.
Also, it's easy to learn a language's syntax over a weekend, but it generally takes a lot longer to start being productive and writing idiomatic code in a new language, especially if you're also learning a new platform. That's time that you or your team may not have.
Since ES6 it's even better.
Python not as scalable, Rails is stagnating, the ecosystem doesn't evolve anymore/dying, doesn't play well with SPAs, C# weak to none ecosystem outside of Windows and devs earn a fraction, Java verbose and dev productivity subpar (there was a reason people came up with Scala), Java devs also suffer lower salaries
Not scalable in what way? Every aspect of scalable that I can think of is in no way limited by choosing python as your language.
Mayne that is your problem. Try new stuff. V8 is still one of the fastest and most optimized VMs.
If you reach out to the Java ecosystem you can find libraries, frameworks, and language extensions that make it relatively easy to code in. For example, with Lombok you don't have to write any getters and setters, or catch checked exceptions. Java 11 also makes good improvements to lamdas making method chaining a lot nicer. The Java I write at work is barely more verbose than the TypeScript, maybe 15% more code to do the same thing.
Java devs also get paid really well honestly, pretty sure it's better than the pay for JS and Python actually.
Huh? Rails ships with built-in, no-config webpack support (https://github.com/rails/webpacker#installation) as well as install tasks for the most-popular front-end solutions (https://github.com/rails/webpacker#integrations)