austin

joined 1 year ago
MODERATOR OF
 

If you've played around with version catalogs enough, you will inevitably come to a point when you when you want to also use a BOM in your version catalog. Doing that just feels so...clunky? You need to declare the BOM in the libraries section, and then you have to declare each individual dependency from the BOM as a library (without a version). Alternatively, you can just skip using the BOM entirely and declare each dependency without the BOM. In either case it's not a great experience and definitely could use some improvement.

I wrote a Gradle plugin (in Kotlin) to automatically generate a version catalog from a BOM so you only have to specify it once, let me know what you guys think!

[–] [email protected] 0 points 8 months ago (1 children)

If you already know Java, Kotlin for Java Developers is free and created by the Kotlin team.

[–] [email protected] 3 points 11 months ago

Much needed change, I wish they made it apply for all go versions though

[–] [email protected] 2 points 1 year ago

The backwards compatibility promises of Go definitely makes upgrading a breeze. Java is pretty much in the same boat (except it maintains bytecode compatibility instead of source). When working with languages that don’t offer these promises it’s always a nightmare to upgrade to newer versions.

[–] [email protected] 1 points 1 year ago* (last edited 1 year ago)

Optional has more syntactic sugar for more complex scenarios / functional call chaining that prevents repetitive if checks

Optional.ofNullable(myObj)
  .map(MyClass::getProperty)
  .map(MyOtherClass::getAnotherProperty)
  .filter(obj -> somePredicate(obj))
  .orElse(null)

This is completely null safe, the function calls are only made if the object is not null

[–] [email protected] 1 points 1 year ago (1 children)

I had never heard of Phaser, but it looks pretty cool. I just read Baeldung's Guide to Phaser and correct me if I'm wrong, but doesn't it kind of seem like a race condition (it could just be how they use it in the examples)?

class LongRunningAction implements Runnable {
    private String threadName;
    private Phaser ph;

    LongRunningAction(String threadName, Phaser ph) {
        this.threadName = threadName;
        this.ph = ph;
        ph.register();
    }

    @Override
    public void run() {
        ph.arriveAndAwaitAdvance();
        try {
            Thread.sleep(20);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        ph.arriveAndDeregister();
    }
}

then

executorService.submit(new LongRunningAction("thread-1", ph));
executorService.submit(new LongRunningAction("thread-2", ph));
executorService.submit(new LongRunningAction("thread-3", ph));

if ph.arriveAndAwaitAdvance(); is called before all of the LongRunningActions are initialized, won't it proceed before it is supposed to?

[–] [email protected] 4 points 1 year ago (1 children)

assuming you propose the idea to migrate to kotlin, it would go something like this:

  • talk to your other developers and see if they feel the same way. get other developer buy-in
  • propose the idea to management with reasons why it would be beneficial
  • management now either buys in and approves kotlin usage, or says it's not worth it

if management says yes, you now have like 20 people who have vetted and agreed with the idea. once you start writing Kotlin it's not like EVERYTHING is all of the sudden Kotlin. it's an iterative process, and hopefully you have test coverage. you can even re-use your existing java tests since the languages are interoperable. Assuming you follow a normal development process, the odds of a catastrophic bug coming out of nowhere to cause millions of dollars of losses wouldn't even cross my mind.

that being said, assuming the current code works decently well, management will have no motivation or reason to approve a total rewrite in a new language. it's more likely that they will only approve starting to trickle in kotlin for new projects or features, which even further reduces the likelihood of a catastrophic bug happening.

[–] [email protected] 2 points 1 year ago

the developers don't have to of left the team to make it legacy code

[–] [email protected] 2 points 1 year ago

I agree it’s unique and not really talked about. It kinda reminds me of Elixir’s doctest

5
Generics in Go (bitfieldconsulting.com)
[–] [email protected] 5 points 1 year ago* (last edited 1 year ago)

Not quite what you’re looking for, but Google does have an official style guide which may be slightly helpful

[–] [email protected] 3 points 1 year ago

I think generally it’s preferably to work in the affirmative, i.e. bar == null? but I’ll admit I don’t stick to this 100% of the time and generally just use whatever feels better / more appropriate in the moment

[–] [email protected] 1 points 1 year ago

The go stdlib uses it a lot. For example, the strings package

view more: next ›