Simple problems, simple solutions, great joy

  • Post category:JavaUI

I’ve been coding for many, many years. I started when I was 13, and that is decades ago. Software development was different back then; programs ran on a single PC, claiming it completely, with text based interfaces (windows were drawn with characters), and maybe, just maybe, there was a shared storage, because some PC had it’s drive shared.

It was also the time when there were not many existing software systems. You had WordPerfect (no WYSIWYG), I remember some kind of simple spreadsheet, and basic bookkeeping software. But that was about it. The world, and all the potential software had, was wide open.

So in the years that followed I wrote many systems. Small ones, to solve small but real problems; an address register for myself, a CRM tool for the local gym, a similar one for the dance school. What a time! It was not much work, especially after MSAcesss was introduced, you got a lot of functionality for the amount of effort you had put in.

(more…)

Continue ReadingSimple problems, simple solutions, great joy

Given When Then

  • Post category:BDDtesting

I have a love-hate relationship with Gherkin, the syntax underpinning Cucumber tests. On the one hand I love the readability, on the other I find the binding of the sentences to step definitions flaky, and the lack of formal structure in those sentences worries me. Like the Maven vs Gradle debate, I’m a fan of structure; it keeps stuff from derailing quickly. (Maven FTW.)

So when I decided to give Cucumber another go for one of my hobby projects, I attempted to get some structure in (more on that later on). But the result was that I wrote this:

    public void test() {
        Scenario.of("Modify Vacation Hours")
                .given(RosterPeriod.on("2022-09-19").exists())
                .and(User.of("peter").isLoggedin())
                .when(Overview.isAccessed())
                .and(VacationHours.forUser("peter").onDate("2022-09-19").isSetTo(20))
                .then(VacationHours.forUser("peter").onDate("2022-09-19").shouldBe(20))
                .and(WeekTotals.forUser("peter").inRosterPeriod("2022-09-19").shouldBe(20,0,0,0,0,0))
                .and(RunningWeekTotals.forUser("peter").inRosterPeriod("2022-09-19").shouldBe(20,0,0,0,0,0))
                .and(Event.who("peter").what("SetVacationHours").user("peter").rosterPeriod("2022-09-19").detailSubstring("hours=20").shouldExist());
    }

Which is the Java equivalent of this Cucumber test:

      Scenario: Modify Vacation Hours
        Given a rosterperiod 2022-09-19 exists
        And user peter is logged in
        When the overview is accessed
        And the vacation hours for peter on 2022-09-19 is set to 20
        Then the vacation hours for peter on 2022-09-19 should be 20
        And the week totals for peter in rosterperiod 2022-09-19 should be 20,0,0,0,0,0
        And the running week totals for peter in rosterperiod 2022-09-19 should be 20,20,20,20,20,20
        And an event with who "peter", what "SetVacationHours", user "peter", rosterdate 2022-09-19 and detail substring "hours=20" should exist

And I started wondering if the Java version is readable enough. Because it damn well fixes all my issues I have with Cucumber.

What do you think?

(more…)

Continue ReadingGiven When Then

We’re looking for a cloud architect…

  • Post category:cloud

Okay, this question is starting to annoy me. Up until recently every company had its own computer infrastructure to maintain. There were people employed for that. And they did a great job, so the software I cooked up was hosted, logged and debuggable. Thank you for that!

Nowadays it seems that every company is looking for a software & cloud architect. Apparently someone decided somewhere that full stack development suddenly needs to include hardware as well.

People…

Friends…

I’m still a software engineer / architect. Just because companies decide to scrap their own hardware and roll it out onto someone else’s, doesn’t suddenly make it my job. We have (had?) people for that, and that specialty hasn’t changed, only the location of the hardware has. The fact that we moved software development and hosting closer together, infrastructure as code, only means we can and should work more closely together. Which is good.

(more…)

Continue ReadingWe’re looking for a cloud architect…

Records instead of named parameters

  • Post category:Java

Actually there is an existing agreement that renaming of method parameters is without consequence. Specific transforms are called out in JLS as binary compatible.

Brian Goetz

I had already mentioned my concern about the strong coupling that named parameters introduce in the first revisited post. Even though the coupling is just a strong as when a custom class is used as a parameter, developers simply do not expected this coupling on named parameters. But the fact that the specification defines that renaming parameters names are to be without consequence, makes named parameters a dead end.

And also because something else has changed since 2013… IDE’s:

And that makes the price to pay for adding named parameters not worth it.

That said, it still was fun to let the idea run through one’s head. And likewise it also is fun to see if there is a way to make this work without renaming parameters… What about using the recently added record classes? Consider this a little creative piece of code (aka it will not compile):

public Rectangle(record Parameters(int width, int height) p) {
    this(p.width(), p.height();
}

new Rectangle(new Parameters(100, 200));
(more…)

Continue ReadingRecords instead of named parameters

Java named parameters re-revisited

  • Post category:Java

Ah! Mr Goetz has kindly reacted on Twitter to the previous blog post, and lifted a piece of the curtain.

You’re mostly focusing on a non-problem; reordering can be done statically without any runtime performance cost (or semi-statically, if linkage is done with Indy.). That’s not any of the issues.

Developer blindness; focusing on part of one problem and not seeing the rest. Yes. I’m very good at developer blindness, that is why I always ask: “Did I miss anything?”. But that reordering can be done totally statically amazes me. As far as I know going from B-A (order of evaluation) to A-B (order of parameters) takes at least some CPU power. But hey, at no performance cost is good news.

But, spend some time thinking about overload selection and binary compatibility, and when that voice in your head says “we can just disallow that” when you get to the hard bits, recognize that is the siren singing to you.

Overload selection. Of course! The minute you start reordering arguments there may be multiple methods that may fit. For which one are you reordering? Consider the following two overloaded methods.

void go(int a, String b, double c);
void go(String b, int a, double c);

Now, if one would write:

go(c=1.0, b="foo", a=2);

Then this call could match any of the two methods, and the compiler would not know for which to reorder the arguments.

(more…)

Continue ReadingJava named parameters re-revisited

Java named parameters revisited

  • Post category:Java

TL;DR named parameters seems to be possible with only a few additional in-memory copies and a bit of stack pointer manipulation. But what will it mean for debugging?

Okay, let me give this another go. In my previous post about named parameters from 2013 I think I made clear why named parameters are a good idea from the perspective of readability. And readability is the second most important aspect of source code, the first being that it should work of course. However I have not been able to convince mr Goetz to add it to Java. And I really tried a few times, ranging from online to face-to-face discussion. His argumentation every time is that it is way more complex than it seems, but unfortunately he never got around to explaining this.

Once you start with named parameters, they have a tendency to attract more and more functionality, so let’s break down what is possible in increasing complexity:

  1. Documentation; the fact that for each argument you can put the name of the associated parameter in the calling statement instead of in a comment (see the 2013 post), makes the call more readable.
  2. Validation; by naming the arguments in the calling statement, the compiler can check if they match the called method’s parameters. It can validate if the intention of the coder matches what is happening.
  3. Ordering; if the order of the names in the call deviate from the method’s signature, the compiler could reorder the arguments to match.
  4. Defaults; when named arguments can be matched to their parameter counterparts, any omissions can be filled with defaults.
void rectangle(int height = 0, int width = 0) { // these parameters have defaults
     // ...
}

void use() {
    rectangle(100, 200); // only from the call it is not obvious what this really defines
    rectangle(height=100, width=200); // better readable, and the compiler can validate
    rectangle(width=200, height=100); // the compiler could fail on this, or reorder based on the signature
    rectangle(width=200); // since all arguments are named, the compiler can infer the value for missing ones
}
(more…)

Continue ReadingJava named parameters revisited

A case for a sealed jar-of-jars

  • Post category:Java

Since last week everyone in the Java developer community has been stumbling over themselves because of the Log4j vulnerability. Once word got out, the log4j maintainers quickly released a fix. So if you were fairly up to date, all you had to do was upgrade a dependency and redeploy. (My project was still using log4j 1.x, so it took just a tad more effort, but that is on me.) Unless you were of course one of the people who were actually using the functionality used by the exploit, but I wager chances are small that is the case.

What I have been pondering about is if the root cause of the vulnerability is in essence really a log4j issue. Yes, log4j made it easily accessible, but the core of the issue is the fact that the JRE is completely based on dynamically loading executable code. It does so via the JNDI method which is used in the log4j vulnerability, but also simply because classes are always loaded from the file system for all Java applications. Basically moving all security constraints onto the system it runs on.

(more…)

Continue ReadingA case for a sealed jar-of-jars

I need help

One of the defining qualities of a good developer, in my opinion, is to know when to ask for help. And I’ve been battling this issue for way to longer than I should have. But since this is a solo open source project, it is a bit of special circumstance, normally I would have asked a colleague to have a look with me ages ago. Anyhow, if any Java developer with a Tesla wants to help out, that would be highly appreciated!

2021-10-04: it turns out Tesla has added a Google recaptcha to the login procedure, which is loaded with a delay, making it impossible to monitor on the web. This missing recaptcha probably is what is triggering the HTTP 500.

(more…)

Continue ReadingI need help

Covid-19 vaccination – yes, it’s a free choice, but…

I have been getting a lot of “free choice” stories in my stream the last weeks. High moral talk about why people did not get vaccinated against Covid, and about respecting choices. It is really starting to annoy me. So in light of the other important right, free speech, I’m voicing my opinion about Covid vaccination and free choice.

(more…)

Continue ReadingCovid-19 vaccination – yes, it’s a free choice, but…

Naming Docker container images

  • Post category:dockerJava

This is something I’ve needed to get off my chest; I really and truly don’t understand the logic behind the scheme of Docker container image names. The first time I tried to grasp it, I got mentally stuck, because it feels to me it blatant ignores any convention. At the moment it is a matter of accepting that this it how it works, but my neurotic side keeps protesting every time I tag an image. Let me explain the beef I have, and then maybe someone can enlighten me.

(N.B. I’m using “docker” in this post, but I actually am using “podman”. But their APIs are identical, so because docker is better known, I’m typing “docker” in this post.)

When you create a new image using the “docker build” command, the newly created image is uniquely identified by a hash, something in the line of 21df6af2a82e0135661ce18a621112450992914e1fcfc0edb285c332318e3e23. This id is totally impossible to convey to other people, so Docker has the possibility to add tags to images. A typical build command looks like

$ docker build --tag my-tag .

This is will use the Dockerfile (Containerfile for podman) to generate an image and add it to the local registry. You can see this by executing a list command:

$ docker images

REPOSITORY        TAG             IMAGE ID      CREATED         SIZE
localhost/my-tag  latest          99bd5445f871  22 minutes ago  280 MB

Wait! What? What is the localhost doing there? And latest?

(more…)

Continue ReadingNaming Docker container images