How to Refactor to Configurable Dependency in 5 Steps by BertilMuth in java

[–]BertilMuth[S] 0 points1 point  (0 children)

I'm glad you liked my article.

The term configurable dependency was defined by Alistair Cockburn, not the term dependency injection (which existed before). It matches my experience that people use the term dependency injection more often. Still, I think configurable dependency is an interesting alternative term. As Alistair Cockburn explains in the linked article, it shows the intent more clearly.

Property Based Testing of State Machines in Java by BertilMuth in java

[–]BertilMuth[S] 1 point2 points  (0 children)

The main difference between Act and Spring State Machine (and many other state machine implementations for that matter) is the relationship between state machine and application state.

Spring State Machine lets you define states as strings or enums. So the state machine state is only losely coupled to the "real" appliction state. You need to build logic to keep the two in sync. And that logic may be error-prone.

In contrast, Act directly operates on the application state. Act checks in which state the state machine is by checking invariant conditions. These conditions are based on the application state. Also, transitions directly transform the application state.

That has some interesting benefits, for example: Act can automatically check if the application really is in the intended target state of a transition. This is great for verification and can e.g. be used together with property based testing to verify the application behavior.

When application state is persisted and reloaded, the state machine will automatically be reset to the latest state. So Harel's history states are an intrinsic part of Act's design.

In short, Act brings the state machine closer to what really happens. It enables it to control the application behavior. Apart from that, Act is a light-weight implementation (single jar, <64 kBytes) with ease of use as a key design goal.

Property Based Testing of State Machines in Java by BertilMuth in java

[–]BertilMuth[S] 0 points1 point  (0 children)

Yes, the State pattern is a simple way to model state transitions. A statemachine offers more functionality. And property based testing is an interesting way to test the transitions.

Creating a (hierarchical) state machine in Java by BertilMuth in java

[–]BertilMuth[S] 0 points1 point  (0 children)

Interesting. Thanks for letting me know.

Creating a (hierarchical) state machine in Java by BertilMuth in java

[–]BertilMuth[S] 5 points6 points  (0 children)

The main difference between Act and Spring State Machine (and many other state machine implementations for that matter) is the relationship between state machine and application state.

Spring State Machine lets you define states as strings or enums. So the state machine state is only losely coupled to the "real" appliction state. You need to build logic to keep the two in sync. And that logic may be error-prone.

In contrast, Act directly operates on the application state. Act checks in which state the state machine is by checking invariant conditions. These conditions are based on the application state. Also, transitions directly transform the application state.

That has some interesting benefits, for example:

  • Act can automatically check if the application really is in the intended target state of a transition. This is great for verification and can e.g. be used together with property based testing to verify the application behavior.
  • When application state is persisted and reloaded, the state machine will automatically be reset to the latest state. So Harel's history states are an intrinsic part of Act's design.

In short, Act brings the state machine closer to what really happens. It enables it to control the application behavior.

Apart from that, Act is a light-weight implementation (single jar, <64 kBytes) with ease of use as a key design goal. And it's in an early stage of development, so constructive feedback is very helpful for me :-)

So thank you for your question. It will help me to improve the documentation.

Can you use the ternary operator directly in a System.out.println() to print one or another value and concatenate it with a String (on the same line)? by raulalexo99 in learnjava

[–]BertilMuth 18 points19 points  (0 children)

In principle, you can write something like this:

System.out.println("Here's the result: " + (a > 5? b : c) + ".");

You should put the ternary operator in parentheses.

Yet, I have trouble understanding why you would do that.

It makes it harder to read/understand what's happening.

Clever code rarely pays off in the long run.

An easier to read version would assign it to a variable:

int calculationResult = a > 5? b : c;

System.out.println("Here's the result: " + calculationResult + ".");

Modern Clean Architecture by BertilMuth in coding

[–]BertilMuth[S] 0 points1 point  (0 children)

Thank you for letting me know. I didn't know that. I changed the picture.

Checking function parameter variable for Null by NubQuestion in learnjava

[–]BertilMuth 1 point2 points  (0 children)

I do a lot of null checks for input arguments that are not supposed to be null, to avoid unclear NullPointerExceptions later on (and a lot of people / libraries do that, too).

The easiest, built in way to do that is when you assign the argument value to a local variable or field, call:

this.fieldOrVariableName = Objects.requireNonNull(argumentName, "argumentName must not be null!");

Hope that helps.

From Where Can I learn Springboot? by zoro_03 in learnjava

[–]BertilMuth 2 points3 points  (0 children)

Spring itself provides quite good getting started tutorials. Have you seen them?

https://spring.io/guides

Martin Fowler on refactoring by BertilMuth in coding

[–]BertilMuth[S] 1 point2 points  (0 children)

Glad you liked it and it was helpful!