News for hackers. Stuff that matters.
Re:Has UML died without anyone noticing? by DaiPlusPlus on Sunday April 25, 2021 @04:31PM (#26936387)
> Low Code or even No Code

I look at the code I'm writing (mostly C# thesedays) and I consider the _information-theoretic_ view of the program code I'm writing, and I see a major problem is that even syntactically terse languages (like C# compared to its stablemate VB.NET) still requires excessive, even redundant code in many places (e.g. prior to C# 9.0, defining an immutable class requires you to repeat names 3 times and types twice (constructor parameters, class properties, and assignment in the constructor body) which alone is a huge time-sink.

The most tedious work I do right now is adding "one more" scalar or complex data-member that has to travel from Point A in Method 1 to Point B in Method 2 - I wish I could ctrl+click in my IDE and say "magically write code that expresses the movement of this scalar piece of data from here to here" and that would save me so much time.

At least in modern languages like C# 9.0, Kotlin, and Swift (and C++ with heavy abuse of templates) a lot of the tedium can be eliminated - but not in the granddaddy of OOP languages: Java. Still to this day, I have absolutely no idea how people can write Java for line-of-business applications (its bread-and-butter!) and remain sane from having to manually manage data-flow, implementing Java Beans, and manually writing by-hand getter-and-setter methods...

Re:Has UML died without anyone noticing? by piva00 on Sunday April 25, 2021 @05:30PM (#26936879)
> but not in the granddaddy of OOP languages: Java. Still to this day, I have absolutely no idea how people can write Java for line-of-business applications (its bread-and-butter!) and remain sane from having to manually manage data-flow, implementing Java Beans, and manually writing by-hand getter-and-setter methods...

Because... We don't. IDEs and code generators have replaced a lot of the more stupid boilerplate. Not that there isn't a lot of stupid boilerplate in Java but it's been greatly reduced by tooling.

Still, I don't work with Java because I like it, I work with Java because it works and has a great ecosystem, the tooling around it make it bearable and without it I'd have definitely have jumped ship a long time ago.

I'm not only a Java developer, I've worked with Go, Python, Clojure, Ruby, JavaScript, Objective-C, PHP and down to ASP 3.0. Java is still the language that employed me the most and the longest, I have no love for it apart from the huge ecosystem (and the JVM gets some kudos) but it works well for larger codebases with fluid teams.

Re:Has UML died without anyone noticing? by cratermoon on Sunday April 25, 2021 @06:14PM (#26937230)
Ward Cunningham once noted that because a programmer can input incomplete, or minimal, code, then push a few buttons to autogenerate the rest, that there's a smaller language inside Java. Since he made that remark a number of other JVM languages have sprung up that try to be less verbose. One of them is Groovy, which uses type inference and other semantics to reduce duplication (or "stuttering" as Go calls it").

The issue now with Java is that it's such a big language and it's accumulated so much from many different paradigms that experience in "Java" doesn't always transfer across different companies or teams. Some teams hew closely to OO design and patterns, others use a lot of annotations and dependency injection, still others have gone fully functional since Java 8.

And then there are shops like one of my employers, where a large codebase and poor teamwork has resulted in a mishmash of all of the above, plus some sections that have no organizing principles at all.

Re:Has UML died without anyone noticing? by DaiPlusPlus on Sunday April 25, 2021 @07:20PM (#26937661)
> Some teams hew closely to OO design and patterns

I maintain that design-patterns are just well-established workarounds for limitations baked into the language - and we get used to them so easily that we rarely question why we’ve even built-up an entire mechanism for programming on-top of a programming language that we never improve the underlying language to render those design-patterns obsolete. (I guess the language vendors are in cahoots with Addison-Wesley...)

For example, we wouldn’t need the Visitor Pattern if a language supported dynamic double-dispatch. We wouldn’t need the adapter, facade, or decorator patterns if a language supported structural typing and/or interface forwarding. We wouldn’t even need to ever use inheritance as a concept if languages separated interface from implementation, and so on.

Better answer: the only real OOP system is Smalltalk.

Re:Has UML died without anyone noticing? by cratermoon on Sunday April 25, 2021 @07:35PM (#26937771)
> design-patterns are just well-established workarounds for limitations baked into the language

Strict functional programmers have been saying that for years. They may be workarounds, but as patterns they have value in allowing one programmer to structure code in a way that is recognizable to another, even months later. You could say that a steering wheel, gas pedal, and brakes are workarounds for limitations baked into the automobile we wouldn't need if cars could drive themselves, but still value the fact that the steering wheel and the rest of the controls for a driver generally look and work the same across vehicles.

Re:Has UML died without anyone noticing? by DaiPlusPlus on Sunday April 25, 2021 @07:55PM (#26937895)
Right you are - but my point is that language designers (especially Java’s) aren’t evolving their languages to render the more tedious design-patterns obsolete - instead they seem to accept the DPs are here to stay.

Take the singleton pattern for example. It’s not perfect: it only works when constructors can be marked as private and/or when reflection can’t be used to invoke the constructor to create a runtime-legal second instance. A better long-term solution is to have the language itself natively support passing a reference to static-state, which completely eliminates the risk of a private ctor invocation - but that hasn’t happened.

OOP Design Patterns are like JavaScript polyfills: they enable things that should be part of the native platform. They’re fine to keep around for a few years when they’re new, but when you’re still using what is essentially an aftermarket add-on for 5+, 10+ or even 25+ years you need to ask if it’s the way things should be or not...

Re:Has UML died without anyone noticing? by piva00 on Sunday April 25, 2021 @07:49PM (#26937860)
Patterns are commonly (but not only) symptoms of some failure of features on the language but at the same time they are just vocabulary.

Patterns exist in functional programming as well, any map/reduce operation is a pattern, any monad is a pattern. It's a proven way to achieve a goal, it's easy to compartmentalise under a moniker and refer to the whole repeatable chunk with a name.

Unfortunately a lot of people only learn how to properly apply design patterns after doing it wrong and/or overdoing it (mea culpa here!). It's easy to spot the bad smells after you've been burnt 2-3 times.

Re:Has UML died without anyone noticing? by closeparen on Sunday April 25, 2021 @11:23PM (#26938942)
If map and reduce were design patterns, you’d be writing out the iteration bits every time you used them. Instead map and reduce are abstractions, and you only have to plug in your unique functions and values.
Re:Has UML died without anyone noticing? by juki on Monday April 26, 2021 @12:17AM (#26939212)
piva00 probably meant that implementing map and reduce for a data structure, rather than the use of them, is a design pattern.
Re:Has UML died without anyone noticing? by piva00 on Monday April 26, 2021 @03:27AM (#26940160)
That was my point, thanks for clarifying it :)
Re:Has UML died without anyone noticing? by mgarus on Tuesday April 27, 2021 @08:20AM (#26954895)
This reminds me of a talk by Rich Hickey [0], where he introduces the Transducer pattern, which is actually an abstraction for map/reduce/fold/filter etc.

(But I'm not trying to invalidate your claim that patterns exist in FP in general, only that specific case. Afaik, the Transducer abstraction isn't even widely-known nor used.)

[0]: https://www.youtube.com/watch?v=6mTbuzafcII

Re:Has UML died without anyone noticing? by smiga_ on Monday April 26, 2021 @04:16AM (#26940413)
What resources would you recommend for learning more about design patterns that are essentially missing language features?
Re:Has UML died without anyone noticing? by DaiPlusPlus on Monday April 26, 2021 @09:10AM (#26942131)
By writing enough code using design-patterns that you see a pattern to the usage (and abusage) of design-patterns - and get plenty of experience with other languages and paradigms where said patterns are irrelevant.
Re:Has UML died without anyone noticing? by cratermoon on Monday April 26, 2021 @09:36PM (#26950755)
Re:Has UML died without anyone noticing? by piva00 on Sunday April 25, 2021 @07:42PM (#26937819)
I'd agree with that statement. I feel that I have settled in a few frameworks that I consider modern but mature and stable, with a good job market. For that I had to learn these smaller languages inside Java.

And not only smaller languages, the tool set as well. Maven and Gradle for a start, and Gradle is its own Universe of little quirks and "what the fuck" moments. IDEs have a learning curve (but I learned vim and emacs before using any IDE so knew how steep learning curves work) and if you manage to use their features it can help immensely your productivity. Frameworks such as Spring have enough pull that it's easy to find interesting projects with it, I think that the direction of Spring Boot is pretty good for modern tech enterprises, at least for part of the stack.

Boring technology has its place, it's a hassle you have to learn a pretty big set of tools to be productive in Java but when you do you can actually accomplish a lot with multiple teams and a scale of hundreds to thousands of engineers.

You can also shoot yourself on the foot pretty easily, in massive scale, if the people taking decisions are architecture astronauts and not battle-hardened engineers who have suffered through incomprehensible code and piles over piles of mishmash of technologies and failed frameworks. Keeping the tech stack simple, boring and focused on a small set of tools has its benefits on scale.

Re:Has UML died without anyone noticing? by xwolfi on Sunday April 25, 2021 @07:21PM (#26937667)
Groovy is a nightmare. We now reject candidates who advocate for it in production during interviews and we warn those who do say they d never dare there but use for testing.

Who cares if you have to write setters and getters by clicking a button in IntelliJ, or have to explicit your types rather than ask every subsequent readers to use their brain as a type inference compiler.

Typing clear code isn't a problem Groovy should have solved by making it all implicit, at the cost of having non compiled production code. A code should never fail at runtime because you made a function name typo that it couldnt tell you about any other time for free.

Re:Has UML died without anyone noticing? by signal11 on Sunday April 25, 2021 @08:12PM (#26938012)
A lot of this also applies to other interpreted languages widely used in production, such as Ruby, Python and Clojure.

You don’t like interpreted languages in production, fine. But rejecting candidates who think differently from you just creates a monoculture and reduces the chance that you learn anything new, beyond reinforcing your own convictions.

Re:Has UML died without anyone noticing? by jnwatson on Sunday April 25, 2021 @11:48PM (#26939076)
Millions of lines of production Python code do just fine by doing the thing you should have been doing all along: testing.
Re:Has UML died without anyone noticing? by closeparen on Sunday April 25, 2021 @11:38PM (#26939018)
How rational this is depends on your testing culture. With a comprehensive test suite, the guarantees offered by a compiler are not very important. The software goes through all its runtime paces before production anyway.

If you’re not going to write any tests, then obviously compile time is a crucial line of defense.

Most shops will be somewhere in the middle where compiler guarantees offer a real but marginal benefit, to be weighed against other tradeoffs.

Re:Has UML died without anyone noticing? by zozbot234 on Monday April 26, 2021 @05:17AM (#26940707)
The point is not "let's just not write any tests". With a compiler that offers meaningful guarantees, you can write more worthwhile tests than "does this function always take/return integers".
Re:Has UML died without anyone noticing? by closeparen on Monday April 26, 2021 @12:04PM (#26944092)
If you’re passing or returning values of the wrong type, it’s going to blow up one of your tests. Asserting on a value implicitly asserts its type. Passing a value and not getting a runtime error for your trouble, pretty strongly indicates that it’s the right type.
Re:Has UML died without anyone noticing? by corty on Monday April 26, 2021 @04:37AM (#26940519)
Writing tests instead of utilizing the compiler is wasted time and effort. And it is one of the worst kinds of code duplication, because you are reimplementing all the type-checking, bounds-checking, etc. Usually badly, buggy and again and again. And since usually the test suite doesn't have tests for the tests, you will only notice if something breaks in the most inopportune occasion possible.
Re:Has UML died without anyone noticing? by jnwatson on Monday April 26, 2021 @10:54AM (#26943136)
In unit testing for dynamically typed languages, very rarely do you make explicit type checks. The type checking naturally falls out of testing for correct behavior.

The "tests for the tests" is code coverage.

Re:Has UML died without anyone noticing? by cratermoon on Sunday April 25, 2021 @07:40PM (#26937807)
> A code should never fail at runtime because you made a function name typo that it couldnt tell you about any other time for free.

So you also reject all dynamic and weakly typed languages? No JavaScript, Objective-C, PHP, Python, Ruby, Lisp, or Tcl? No type coercion at runtime?

> at the cost of having non compiled production code

Groovy can be compiled to the same bytecode as Java.

Re:Has UML died without anyone noticing? by kazinator on Sunday April 25, 2021 @09:32PM (#26938400)
If the language doesn't help you with a function name typo, that's crap dynamic. Not only is that not a feature or benefit of dynamic, but it fuels unfair strawman arguments against dynamic.

Here is something I made largely for my own use:

  This is the TXR Lisp interactive listener of TXR 257.
  Quit with :quit or Ctrl-D on an empty line. Ctrl-X ? for cheatsheet.
  TXR is enteric coated to release over 24 hours of lasting relief.
  1> (file-put-string "test.tl" "(foo (cons a))")
  t
  2> (compile-file "test.tl")
  * test.tl:1: warning: cons: too few arguments: needs 2, given 1
  * test.tl:1: warning: unbound variable a
  * test.tl:1: warning: unbound function foo
  * expr-2:1: variable a is not defined
That's still a strawman; it only scratches the surface of what can be diagnosed.
Re:Has UML died without anyone noticing? by gher-shyu3i on Sunday April 25, 2021 @08:29PM (#26938107)
For any non-trival program (more than a couple of files/pages long), dynamic and weak typing are a no-go.
Re:Has UML died without anyone noticing? by cratermoon on Sunday April 25, 2021 @08:42PM (#26938164)
How strongly typed is C? Are non-trivial programs in C a no-go? Would a LISP program more than a couple of pages long be forbidden?
Re:Has UML died without anyone noticing? by gher-shyu3i on Sunday April 25, 2021 @08:47PM (#26938181)
There are toolings that patch C's shortcomings, and there's a reason better typed languages (e.g. Rust) are making strides in C's domain.
Re:Has UML died without anyone noticing? by jjgreen on Monday April 26, 2021 @04:11AM (#26940396)
TIOBE gives C 14.32% (1) against Rust 0.49% (29), so "strides" might be over-egging the pudding.
Re:Has UML died without anyone noticing? by gher-shyu3i on Monday April 26, 2021 @10:49AM (#26943075)
Historic vs future trends.
Re:Has UML died without anyone noticing? by thrwaeasddsaf on Monday April 26, 2021 @05:58AM (#26940910)
Which tools patch C's shortcomings?
Re:Has UML died without anyone noticing? by gher-shyu3i on Monday April 26, 2021 @10:48AM (#26943068)
Static analysis tools and subsets like MISRA C.
Re:Has UML died without anyone noticing? by thrwaeasddsaf on Monday April 26, 2021 @12:21PM (#26944345)
Do you have a good one in mind? All the open source tools I've tried are MISRAble
Re:Has UML died without anyone noticing? by gher-shyu3i on Tuesday April 27, 2021 @06:13AM (#26954041)
Nope, I haven't been working with C recently.
Re:Has UML died without anyone noticing? by cataphract on Sunday April 25, 2021 @08:04PM (#26937960)
I see where you're coming from, having used Groovy for a few years (in Grails, mostly) but I think you're also overstating your case.

Groovy is very quirky, and it's good at turning compile errors into runtime errors (@CompileStatic negates many of its advantages like multiple dispatch) and making IDE refactoring less effective. But the again, so is Spring. This got better when Java configuration was introduced... and then came Spring Boot, which is a super leaky abstraction, with default configuration that automatically backs off depending on arbitrary conditions (!). And yet people find it valuable, because it reduces boilerplate.

These days, I use Groovy mostly in testing (and Gradle), and it can really make tests more expressive.

Re:Has UML died without anyone noticing? by etripe on Monday April 26, 2021 @06:24AM (#26941053)
> IDEs and code generators have replaced a lot of the more stupid boilerplate. Not that there isn't a lot of stupid boilerplate in Java but it's been greatly reduced by tooling.

I've been dealing with Java for about four years in an academic setting, not professional. When observing Java code in workplaces, the code bases have universally been bloated monstrosities composed mainly of anti-patterns - but that was hopefully down to the era these applications were written in (J2EE, Struts, etc).

My experience is that:

* Auto-generated code is still visual (and debugging) noise

* Annotations like Lombok's are great, but are "magic" abstractions, which I find to be problematic. They add cognitive load, because each specific library has its own assumptions about how you want to use your code, as opposed to built-in language constructs.

* Especially for Lombok, I can't help but think adding @Getter and @Setter to otherwise private fields is a poor workaround for a simple language deficiency: not having C#'s properties { get; set; }. I feel the same about libraries that try to circumvent runtime erasure of generic types.

* Compared to C#'s ASP.NET (core), I find fluent syntax configuration with sane defaults and "manual" DI configuration much more manageable and maintainable than auto-magic DI as in Spring, because at least it's explicit code.

* Java tooling (and if previous points weren't, this is definitely a subjective stance) just seems inferior and to set a low bar in terms of developer experience - maven or gradle compared to nuget, javac compared to dotnet CLI, executable packaging... As to other tooling, I suppose you're mainly referring to the IntelliJ suite?

I think C# (and by extension, Kotlin) had the right idea in seeking a balance through removing as much boilerplate as possible in base language constructs. Adding libraries is fine, but shouldn't be a workaround to evolving the language.

Re:Has UML died without anyone noticing? by piva00 on Monday April 26, 2021 @06:38AM (#26941125)
I agree with all of your points, including C# and Kotlin approach.

At the same time, a lot of that are artefacts of decisions made early in Java such as backwards compatibility.

The same for tooling, a lot of tools are results of its time, Ant, Maven and now Gradle.

Lombok has its pros and cons, I use it sometimes but had issues with Lombok and Java upgrades due to how Lombok writes out its bytecode.

I haven't touched javac in more than a decade so I don't really care about it, it's been abstracted away by my build tools (and I agree, the build tools are less-than-optimal).

Again, I agree with all the critics, at the same time just given how large the Java installation base is and by having to go through the Python 2 vs Python 3 migration path, debacles, etc., I still prefer to have all this cruft that is known, well discussed online, has documentation about its quirks rather than a moving target of language features over the last 20-25 years.

Java is too big due to all the evolution it went through, it could have taken different paths and modernised the language? Yes, at the expense of some core design decisions in the beginning. Do I agree with all these decisions? Nope, but who agrees to all design decisions made by their programming language designers?

Re:Has UML died without anyone noticing? by DaiPlusPlus on Monday April 26, 2021 @09:21AM (#26942235)
> Compared to C#'s ASP.NET (core), I find fluent syntax configuration with sane defaults and "manual" DI configuration much more manageable and maintainable than auto-magic DI as in Spring, because at least it's explicit code.

Fluent-syntax, as it exists today, needs to die in a fire. It's horrible. It's abusing a core key computer-science concept (return values) and turning it into something that exists to only save a few keystrokes.

1. You have no way of knowing if the return-value is the same object as the subject or a new instance or something else.

2. It doesn't work with return-type covariance.

3. You can't use it with methods that return void.

4. You can't (easily) save an intermediate result to a separate variable.

5. You can't (easily) conditionally call some methods at runtime.

6. There is no transparency about to what extent a method mutates its subject or not. This is a huge problem with the `ConfigureX`/`UseY`/`AddZ` methods in .NET Core - I always have to whip-out ILSpy so I can see what's really going on inside the method.

Some libraries, like Linq and Roslyn's config use immutable builder objects - but others like ConfigureServices use mutable builders. Sometimes you'll find both types in the same method-call chain (e.g. Serilog and ImageProcessor).

What languages need is to bring back the "With" syntax that JavaScript and VB used to have - and better annotations or flow-analysis so that the compiler/editor/IDE can warn you if you're introducing unwanted mutations or unintentionally discarding an new immutable return value.

Re:Has UML died without anyone noticing? by etripe on Monday April 26, 2021 @04:44PM (#26947865)
> exists to only save a few keystrokes.

It does that, but it also makes your code read more like natural language. Perhaps I was careless in my wording, as I meant to point to manual, explicit configuration rather than fluent syntax per se.

As to your bullet points: I can see where you're coming from. I still think it's better than the invisible side effects and invisible method calls you get with annotations.

> What languages need is to bring back the "With" syntax that JavaScript and VB used to have

As far as I know, With... End With is a weird cross between "using" in C# and object initialisers. How does that help prevent mutations? One of the code examples (0) even explicitly mentions:

   With theCustomer
        .Name = "Coho Vineyard"
        .URL = "http://www.cohovineyard.com/"
        .City = "Redmond"
   End With
I honestly don't see the big difference with either:

   var customer = new Customer {
       Name = "Coho Vineyard",
       URL = "http://www.cohovineyard.com/",
       City = "Redmond"
   };
or:

   var customer = Customer
      .Name("Coho Vineyard")
      .URL("http://www.cohovineyard.com/")
      .City("Redmond")
      .Build();
[0] https://docs.microsoft.com/en-us/dotnet/visual-basic/languag...
Re:Has UML died without anyone noticing? by throwaway3699 on Sunday April 25, 2021 @09:30PM (#26938383)
AutoValue makes a lot of this easier, but you're right that vanilla Java is quite terse, much more than needed.
Re:Has UML died without anyone noticing? by jerf on Monday April 26, 2021 @10:01AM (#26942563)
"The most tedious work I do right now is adding "one more" scalar or complex data-member that has to travel from Point A in Method 1 to Point B in Method 2 - I wish I could ctrl+click in my IDE and say "magically write code that expresses the movement of this scalar piece of data from here to here" and that would save me so much time."

All of this is possible today and not even that hard (though it's harder than meets the eye, there's a lot of issues that description glosses over that you have to deal with, especially in conventionally-imperative languages). The main problem you face is that the resulting code base is so far up the abstraction ladder that you need above-average programmers to even touch it. (I am assuming that this is merely a particular example of a class of such improvements you would like made.) This is essentially the same reason why Haskell isn't ever going to break out of its niche. You can easily create things like this with it, but you're not going to be hiring off the street to get people to work with it.

Or, to put it another way, a non-trivial reason if not the dominant reason we don't see code written to this level of abstraction is the cognitive limitations of the humans writing it.

I know HN doesn't really like this point sometimes, to which I'd ask anyone complaining if they've mentored someone a year or two out of college and fairly average. You can't build a software engineering industry out of the assumption that John Carmack is your minimum skill level.

Re:Has UML died without anyone noticing? by closeparen on Sunday April 25, 2021 @11:19PM (#26938923)
Rich Hickey and Clojure have a low-tech solution for you: use maps. This “wiring through all the layers” problem is basically self-imposed by the use of static typing for data objects. Instead you should mostly pass around maps, validate that the keys you care about are present, and pass along the rest.

Of course your Java peers aren’t going to be happy about this, so in some ways a new language is needed to establish a context for this norm. But the limitation isn’t physical, not even in Java.

Re:Has UML died without anyone noticing? by 411111111111111 on Sunday April 25, 2021 @05:03PM (#26936647)
I use java8 at my dayjob.

It's been years since I did any of that, as Lombok and spring boot generate that code for you.

Immutable classes get a @Value and maybe @Builder annotation, muteable ones get @Setters etc.

Springs auto wiring for beans is sadly magical however, so much harder to figure out what went wrong if you have any issues...

Re:Has UML died without anyone noticing? by tharkun__ on Sunday April 25, 2021 @07:41PM (#26937811)
It's weird to me how you find the magic of spring sad while you find the magic of Lombok acceptable.

Lombok requires that you use a supported build system and IDE and while all the currently relevant ones are supported that is no guarantee. Needs plugins and agents that support your various tools' versions including the JVM itself. I've been in that hell before with AspectJ and the aspectJ compiler vs eclipse plugin (version incompatibilities that made it impossible to work efficiently until they fixed it all up).

Disclaimer: last company we used Lombok. Current company we are switching certain things to Kotlin instead. data classes FTW for example. I do miss magic builders. Builders are awesome. Building the builder is tedious ;)

Re:Has UML died without anyone noticing? by hamandcheese on Sunday April 25, 2021 @09:07PM (#26938285)
Lombok magic doesn’t span across files. Look at the class, see the annotations, and as long as you have even a trivial understanding of what Lombok is, you can grok it. It’s basically like a syntax extension.

Spring on the other hand... autowired values everywhere, and at least for me (who doesn’t work with Spring day in and day out) it’s very difficult to understand where they come from.

Re:Has UML died without anyone noticing? by tharkun__ on Monday April 26, 2021 @08:05PM (#26949957)
Don't get me wrong, I've used Lombok and liked it from the working with it and what it saves you aspect.

We do use spring and I've used it for a very long time now. Nothing is magic and not understandable about wiring if you do it right. Unfortunately there are a lot of projects out there that use it in exactly the wrong way if you ask me and then I'd agree with you.

I used to be in a company where we used XML config and everything was wired explicitly. The XML part sucked but with SpringIDE (eclipse at the time) it was Ctrl-clickable to find what's what.

We use Java config with Spring at my current company and I can Ctrl-click my way through it all and find what's what. There's a small corner of 'package-scan'ed stuff that is evil but we are cleaning that up.

Re:Has UML died without anyone noticing? by gher-shyu3i on Sunday April 25, 2021 @08:30PM (#26938118)
Java already has records, better than Kotlin's data classes.
Re:Has UML died without anyone noticing? by unscaled on Sunday April 25, 2021 @09:16PM (#26938331)
How exactly are they better from Kotlin's data classes?

Aside from the fact Java only released non-preview support for records one month ago, they:

  - Don't support inheritance
  - Can't be mutable
  - Don't have a copy method
While Java records are nice, Kotlin data classes are strictly more capable than Java records.
Re:Has UML died without anyone noticing? by tharkun__ on Monday April 26, 2021 @08:01PM (#26949916)
FWIW I think that whether someone wants to use mutable objects or swears by immutability should be their choice, especially for interoperability with legacy code. It can be much easier to 'just go with the flow and be careful' in a legacy code base vs trying to have a clear separation of where immutability has been introduced already and where we still don't use it. Not everything is green field (in fact most stuff isn't) and not every company gives you enough time to always Do The Right Thing (TM).

Copying objects is a well known need and there are countless libraries that try to help you with it. All with their own problems, notably runtime errors vs. compile time safety or pervasive use of reflection.

Re:Has UML died without anyone noticing? by wwwwewwww on Monday April 26, 2021 @03:04AM (#26940034)
Why would you need a copy method for an immutable record?
Re:Has UML died without anyone noticing? by etripe on Monday April 26, 2021 @06:33AM (#26941097)
When applying events, for instance. In F#, you could do:

  match msg with

  | IncreaseCounter cnt ->
   { model with Count = model.Count + cnt }

  | DecreaseCounter cnt ->
   { model with Count = model.Count - cnt }

  | ResetCounter ->
   { model with Count = 0 }

  | ChangeRubric name ->
   { model with Rubric = name, Count = 0 }
The "with" says: copy the original record by value, but change these fields. For completeness' sake: F# also has implicit returns, so the bit between brackets is the function's return value.
Re:Has UML died without anyone noticing? by TomSwirly on Monday April 26, 2021 @03:39AM (#26940243)
Python's dataclasses have a "make a copy with these fields changed" function that's rippingly useful for immutable records.
Re:Has UML died without anyone noticing? by HelloNurse on Monday April 26, 2021 @03:30AM (#26940175)
How would inheritance, mutability and an arbitrary, presumably wrong and misguided "copy method" be a feature?
Re:Has UML died without anyone noticing? by unscaled on Monday April 26, 2021 @07:25AM (#26941384)
Why do you think copy methods are "presumably wrong and misguided"?

For the rest, I agree that in 99% of the cases inheritance and mutability are not needed if you're using greenfield Kotlin libraries. But they are unfortunately often necessary in the Java world.

Mutable data classes are especially quite useful for reducing boilerplate when creating classes that implement the Fluent Builder pattern, which is unfortunately quite necessary if you don't have a copy method...

Re:Has UML died without anyone noticing? by gher-shyu3i on Monday April 26, 2021 @10:48AM (#26943062)
Copy methods are in the works, and Java's pattern matching will be better than Kotlin's.
Re:Has UML died without anyone noticing? by the-alchemist on Monday April 26, 2021 @12:19PM (#26944324)
Lombok is great, but Immutables is even better! https://github.com/immutables/immutables
Re:Has UML died without anyone noticing? by rahoulb on Monday April 26, 2021 @02:23AM (#26939815)
> the granddaddy of OOP languages: Java

I disagree with this statement. Java just happened to become popular due to its C style syntax and various accidents of history.

Smalltalk is the true grand daddy of OOP languages and none of the issues you talk about apply there.

Re:Has UML died without anyone noticing? by philwelch on Sunday April 25, 2021 @04:52PM (#26936573)
> Still to this day, I have absolutely no idea how people can write Java for line-of-business applications (its bread-and-butter!) and remain sane from having to manually manage data-flow, implementing Java Beans, and manually writing by-hand getter-and-setter methods...

Lombok, at the very least, eliminates “manually writing by-hand getter-and-setter methods” (https://projectlombok.org/).

Re:Has UML died without anyone noticing? by DaiPlusPlus on Sunday April 25, 2021 @07:31PM (#26937738)
Thank you. I stopped using Java on a regular basis around late-2009-ish, which was before Lombok became really popular (as far as I know) so it is encouraging to hear that writing Java in-practice isn’t as bad as I feared.

Still... I feel strongly that Java eventually needs to adopt object-properties and reified-generics for it to stay relevant - otherwise it offers fewer and fewer advantages over competing languages - at least for greenfield projects at first, and eventually it’ll start being _uncool_ and fail to attract newer and younger devs to keep the ecosystem alive. Then we’ll end up with the next COBOL (well, more like the next Pascal/Delphi...)

Re:Has UML died without anyone noticing? by philwelch on Monday April 26, 2021 @12:05AM (#26939167)
That seems unnecessarily harsh towards Pascal/Delphi. I’d stick with the COBOL metaphor.

I’d also add that while Java does suck in some fairly obvious ways, most languages suck and at least Java can actually run concurrent threads in parallel.

Re:Has UML died without anyone noticing? by lmm on Sunday April 25, 2021 @07:42PM (#26937815)
Lombok ends up having all the costs of using a better JVM language (you still need to integrate it into your coverage tools, code analyzers etc.) but with few of the benefits. I used to use Lombok but in the end it was easier and better to just use Scala.
Re:Has UML died without anyone noticing? by philwelch on Sunday April 25, 2021 @11:56PM (#26939114)
That’s fair. When I was writing Java code I wanted desperately to evaluate Kotlin, for the obvious reasons you’d expect, but there was not an easy Lombok-to-Kotlin migration path.

I probably would not choose Java with Lombok for a greenfield project today, were it up to me. But if I was forced to use Java, I would use Lombok. I was forced to use Java and I did use Lombok, and it didn’t really suck that bad.

Re:Has UML died without anyone noticing? by lmm on Wednesday April 28, 2021 @07:04PM (#26975364)
I don't think any reasonable decisionmaker would approve Lombok and not Kotlin or Scala. (But I'm aware that many large organisations end up making unreasonable decisions).

The gap between post-8 Java and Kotlin is pretty small yeah. Though you have to write a lot of async plumbing yourself, and not having delegation is a real pain.

Re:Has UML died without anyone noticing? by philwelch on Wednesday April 28, 2021 @11:14PM (#26977017)
> I don't think any reasonable decisionmaker would approve Lombok and not Kotlin or Scala. (But I'm aware that many large organisations end up making unreasonable decisions).

For whatever reason, it’s a lot easier for most organizations to sign off on using a specific library for an existing programming language, even one as transformative as Lombok, than to sign off on using a different programming language, even one as backwards-compatible as Kotlin. Often they are categorically different decisions in terms of management’s interest in micromanaging them: they might default-allow you to include libraries and default-disallow you to write code in a different language.

In this respect, Lombok is really handy for a very common form of unreasonable organization :)

Re:Has UML died without anyone noticing? by xwolfi on Sunday April 25, 2021 @07:16PM (#26937626)
But when you read a novel, it's full of excessive and redundant code.

You don't write code for the machine, you write it for your team. It's fine if it's nice and comfortable, a bit repeated and fluffy, rather than terse and to the point.

Your code is only read by humans.

Re:Has UML died without anyone noticing? by memorysafety on Monday April 26, 2021 @10:39AM (#26942970)
This is exactly my grudge with boilerplate. Code is being read much more often than written.

I don't care if you hand-coded all those buckets of accessors, or your IDE has generated them -- that's irrelevant to that they're still overwhelmingly useless noise. Which I need to read through, which I need to review in PR diffs, skim in "find symbol usage" output, class interface outlines, javadocs, etc etc -- all that 10 as often as during writing. Somehow I'm expected to learn to ignore meaningless code, while producing it is fine?..

Remember the point made in "green languages, brown languages" recent post here on HN? The insight for me there was the source of "rewrite it from scratch" urge which should be very familiar to engineers working in the field. It comes from incomprehensible code or weak code reading skills. Either way, boilerplate does nothing but harm.

So no, while I agree on your point that code exists principally to be read by humans (and as a nice secondary bonus, executed by machines) -- I disagree that boilerplate is "fine" whatever its incarnation. It's not, because it directly damages the primary purpose of code: its readability.

Re:Has UML died without anyone noticing? by aasasd on Monday April 26, 2021 @08:16PM (#26950050)
> Still to this day, I have absolutely no idea how people can write Java for line-of-business applications (its bread-and-butter!) and remain sane from having to manually manage data-flow, implementing Java Beans, and manually writing by-hand getter-and-setter methods...

My long-standing view is that Java's strict and verbose OOP syntax and semantics are an interface for IDEs. People who are hand-coding are practically guaranteed to be baffled by the verbosity, but they forget that Java development was the driver for IDE evolution (afaik), such that now we have ‘extract method’ and similar magic that understands code structure and semantics.

More specifically, OOP works, or should work, as an interface for IDEs that allows to (semi-)programmatically manipulate entities on a higher level, closer to the architecture or the problem domain.

Like you, I wondered if this manipulation can be harnessed and customized, preferably in a simpler way than giving in to the whole OOP/IDE/static-typing tangle and without writing AST-manipulating plugins for the IDE. In those musings I ended up with the feeling that Lisps might answer this very wish, with their macros and hopefully some kind of static transformations. Which are of course manipulating ASTs, but it seems to be done somewhat easier. Alas, predictably I've had no chance of doing any significant work in a Lisp, so far.

Re:Has UML died without anyone noticing? by _void on Monday April 26, 2021 @02:42AM (#26939920)
FYI for c# you have resharper allowing to add parameters to method and it would automatically propagate passing it through several levels up based on references. Guess sometimes all you need to know are the right tools.
Re:Has UML died without anyone noticing? by jjav on Tuesday April 27, 2021 @09:26PM (#26964277)
> granddaddy of OOP languages: Java.

Nowhere near. There was a lot of OOP hype in the early 90s with Smalltalk and C++, so Java just went all-in (everything is in a class) on that trend of the times.

Re:Has UML died without anyone noticing? by caseymarquis on Monday April 26, 2021 @10:46AM (#26943046)
Could you give a concrete example of your problem in a gist or something? I'm curious if it's solvable in C# as is. Sounds like it may be the kind of thing I'm approaching with reflection and attributes right now.
Re:Has UML died without anyone noticing? by TomSwirly on Monday April 26, 2021 @03:36AM (#26940221)
If you're writing in Java, why not write in Kotlin? They're sufficiently compatible you can have Java and Kotlin files in the same directory structure, compiled with the same compiler.
Re:Has UML died without anyone noticing? by peterpost2 on Sunday April 25, 2021 @04:49PM (#26936548)
this resonates so much to me
Re:Has UML died without anyone noticing? by KronisLV on Monday April 26, 2021 @02:31AM (#26939852)
Well, in the case of Java there definitely are ways to minimize the boilerplate. Some of the more common ones that i use:

  - Lombok library ( https://projectlombok.org/ ) generates all of the getters and setters, toString, equals, hashCode and other methods that classes typically should have (JetBrains IDEs allow you to generate them with a few clicks as well)
  - MapStruct library ( https://mapstruct.org/ ) allows mapping between two types, between UserEntity and UserDto for allowing mostly similar objects or ones that are largely the same yet should be separate for domain purposes
  - Spring Boot framework ( https://spring.io/projects/spring-boot ) allows getting rid of some of the XML that's so prevalent in enterprise Java, even regular Spring, and allows more configuration to be done within the code itself (as well as offers a variety of pluggable packages, such as a Tomcat starter to launch the app inside of an embedded Tomcat instance)
  - JetBrains IDE ( https://www.jetbrains.com/ ) allows generating constructors, setters/getters, equals/hashCode, toString (well, there are covered by Lombok), tests, as well as allows for a variety of refactoring actions, such as extracting interfaces, extracting selected code into its own method and replacing duplicated bits, extracting variables and converting between lambdas and also implementing functional interfaces, as well as generating all of the methods that must be implemented for interfaces etc.
  - Codota plugin ( https://www.codota.com/ ) offers some autocomplete improvements, to order them by how often other people used any of the available options, though personally there was a non-insignificant performance hit when using it
As far as i know, there is a rich ecosystem for Java to allow treating the codebase as a live collection of a variety of abstractions which can be interacted with in more or less automated ways, as opposed to just bunches of overly verbose code (which it still can be at the same time). Personally, i really like it, since i can generate JPA annotations for database objects after feeding some tools information about where the DB is and allowing them to do the rest, as well as generating web service code from WSDL (though i haven't used SOAP in a while and noone uses WADL sadly, though OpenAPI will get there).

And then there's attempts like JHipster ( https://www.jhipster.tech/ ) which are more opinionated, but still interesting to look at. I think that model driven development and generative tooling is a bit underrated, though i also do believe that much of that could be done in other, less structured languages, like Python (though that may take more effort) and probably done better in more sophisticated languages, such as Rust.