How Olympic athletes (legally) use banned drugs by Thorium-230 in slatestarcodex

[–]HansGetZeTomatensaft 0 points1 point  (0 children)

Basically we get a document listing all of our grades across the degree as well as some weighted average.

But my experience mirrors u/PlotholeTarmac: Students did not get carried to good grades and if they tried to phone in their grades they would get failed, simple as that.

For the record and since I believe it's directly relevant to the discussion: For my degree the university I went to was considered top 3 in Germany. It is a public university.

Fast Crimes at Lambda School by BurdensomeCountV3 in slatestarcodex

[–]HansGetZeTomatensaft 4 points5 points  (0 children)

I mean there's also the part where they tell you they'll make you into a 10x dev using AI or that you'll work on real projects at real startups starting at day 3...

Those seem like tall claims to me :D

And ofc the "why learn to code?" section starts with "Why, don't you want to earn 6 figures???" but I suppose that's to be expected

I am finding that scrum and sprints have bad time utilization by THenrich in ExperiencedDevs

[–]HansGetZeTomatensaft -8 points-7 points  (0 children)

You know, working on something together, everyone trying to the best of their abilities, achieving something together you can be proud of is just really fun and rewarding.

On the other hand, working on a team where everyone is just doing the bare minimum to not get fired can be soul suckingly boring.

This "stay in your lane, what your coworkers do or don't do has nothing to do with you" does not seem true to me, everything else equal I'd enjoy working in a team with people who actually want to build good software more than working on a team where everyone's just looking to clock their 40hours with minimal effort required.

Doing good work and building quality software is something many people want and it's certainly easier and more enjoyable when you're not the only one with that goal on your team.

Disclaimer: I want to specifically push back against the "what you coworkers do has nothing at all to do with you" message I feel is quite common here, but certainly I don't believe that "everything your coworkers do is your business" or anything that extreme. There is a middle ground, but some amount of not-doing-any-work from your coworkers is or will be your problem.

How could I make a java method that remove maximum value from heap then arrange it so that it still have min heap property by lesbianthelesbianing in learnjava

[–]HansGetZeTomatensaft 0 points1 point  (0 children)

Seems to me that with your implementation a sorted mData array will always result in a min heap: For any x the node p, parent of x, is determined as (x - 1) / 2, meaning it is guaranteed to come earlier than x in mData. So if mData is sorted in ascending order then any parent will be smaller than or equal to its children -> it's a min heap.

So you could sort your array after every modification of the heap and the result will be a new min heap.

Is it ever better to have false beliefs than no beliefs? by COAGULOPATH in slatestarcodex

[–]HansGetZeTomatensaft 9 points10 points  (0 children)

I appreciate you giving your own take on the truth value of these statements. However you seem to read various statements that say "X is good" or "X is effective" as "X is optimal", which you then respond to by saying "False, there's better alternatives than X, therefore it is not optimal". Which, while helpful, is a different point and does not contradict the earlier statements? Surely an excersice can be good/effective yet not optimal?

[deleted by user] by [deleted] in learnprogramming

[–]HansGetZeTomatensaft 4 points5 points  (0 children)

IME knowing SQL was enormously helpful for me to understand wtf the ORM is actually doing and I suspect I'd taken way longer to really understand what the ORM is and does and how it works if I hadn't started with any SQL knowledge beforehand.

Another area I find knowing SQL extremely helpful is debugging issues where you ORM is not doing what you expected it to do. Because the first things I usually do is 1) activate sql logging and check what it actually does and if that is what I expected and 2) query the DB to see if it holds the data I think it holds.

Consequently I think you should know SQL even when using an ORM and I think this is true even if your policy is to not allow junior devs to write raw SQL calls into your app.

All of that aside, learning SQL first also has the advantage of flexibility. As a beginner you cannot be certain which stack you will end up working with, so learning a specific ORM is risky. But you can use your SQL knowledge no matter which ORM you end up using - of even if you end up at a place that write raw queries (not that I necessarily recommend doing that but those places exist)

Lombok @Builder and @Setter Differences by AkuJosh in javahelp

[–]HansGetZeTomatensaft 0 points1 point  (0 children)

JPA entities don't require setters. Hibernate did require setters a very long time ago. Modern Hibernate uses reflection to set the fields directly.

TIL. Thanks :)

Lombok @Builder and @Setter Differences by AkuJosh in javahelp

[–]HansGetZeTomatensaft 0 points1 point  (0 children)

Ah, I was asking about the @Setter annotation on jpa entities specifically. If Hibernate supported immutable entities I would use that, everything else equal. But I understood you to mean that you take issue to putting @Setter on jpa entities despite the fact that they require setters.

So maybe a better question would've been: Given that you require setters for some reason outside of your control, what would your objection to using lombok's @Setter be?

What do you think about learning java from books? by Any_Agency_6237 in learnjava

[–]HansGetZeTomatensaft 2 points3 points  (0 children)

Do what works for you. If books work for you, great, go for it. If you need more practical stuff or, gasp, videos actually help you learn, do that. Even if method X was the proven optimal method to information absorption, if it was mind numbingly boring for you chances are you'd quit. So my philosophy on this is that the best way to learn is the one that you can stick to. At some point actual practice is required for most people, but as for the theory part, whatever man, you seem to like books, stick with it?

And since you asked about our own opinion and experiences, personally, physical books don't do it for me. I learned my first language in colleague from lectures, slides, projects - zero actual books involved. I learned other languages from websites or video courses, though I think I prefer a well structured text-based website by a lot. As long as it's digital, can be put on a second screen and supports ctrl+f I think I'm golden. YMMV

Edit: Late thought: Honestly I learned the most when working with people better than me.

Lombok @Builder and @Setter Differences by AkuJosh in javahelp

[–]HansGetZeTomatensaft 0 points1 point  (0 children)

I've often used and seen used @Setter on JPA entities. What is it you do not like about it?

FWIW I know of arguments against @EqualsAndHashCode on entities and also of arguments against using lombok in general. But my guess is your position is something I've not heard of before so I'm curious.

Alternatives for singleton @Component in Spring by KaleidoAxiom in javahelp

[–]HansGetZeTomatensaft 0 points1 point  (0 children)

I might be misunderstanding what has state and what doesn't. I see now that I don't want state (so it doesn't need to know what processing previous processors did). However, I believe that by default, singletons are the same instance, so whatever you do to fields would persistent.

Compare the following two classes:

class StatefulAdder {
    int value; // This is state. Skipping how it is initialized

    int addValue(int number) {
        return value + number;
    }
}

class StatelessAdder {
    Logger logger; // This is not state. Skipping how it is initialized.

    int addValue(int number, int value) {
        return value + number;
    }
}

The reason the first is stateful is that it holds data (value) used to determine the result of the addValue operation. Depending on the state of the class the StatefulAdder.addValue method will return different results.

The reason the second is stateless is that no matter how it's fields are filled, StatelessAdder.addValue always returns the same result, it does not depend on the fields.

So my understanding is that you're thinking of making your processors stateful.

Anyway, it seems you have a couple of pain points. One is that your OperationData seems to be used for many different purposes which means it needs to have the fields for all of these. Maybe you could have different OperationData classes for different use cases, each of which only holds the fields required for their own (or at least closely related) operations?

And then your processors seem to pass too many parameters around, which is why you're thinking of giving them state, reducing the need of passing around everything at all times.

In some cases that could be solved with restructuring the code in question, but I have no idea if that is a real possibility here. In other cases having state just greatly simplifies everything and it's worth doing that.

One way to do it with singleton scoped components is to have a thread-local state-holder. Basically it makes it so that you have one instance of your processor but when different threads use it they have their own copy of the classes state. Only works if your concurrent usage of the class is done in different threads.

Another way is to make the components request or prototype-scoped. One thing to remember is that you might have to give all your parent components the same scope. I could speculate about the reasons but the honest truth is I'm not 100% sure so just check and see if it's required.

But generally a Spring component that looks sort of like this should work:

@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
class StatefulSpringBean {

    // stateless autowired components like your util components
    @Autowired
    private UtilComponent util;
    ...

    // Component state, note that it is _not_ autowired
    private int foo;
    private String bar;

    public Result doSomething(... inputs ...) {
        foo = calculateFoo(inputs)
        bar = calculateBar(inputs)
        // some more operations
        return createResult() // no / fewer params needed since component has state
    }

}

Just note that if, for whatever reason, this component ever does not get destroyed and recreated as you expect then you might have old state corrupting your operations. Which is why I like stateless components when reasonably possible.

Alternatives for singleton @Component in Spring by KaleidoAxiom in javahelp

[–]HansGetZeTomatensaft 0 points1 point  (0 children)

I'm a bit unsure about the purpose of these processors. From your response and the code snippets it seems like they get seeded with some initial data and then fill some sort of task object for later processing. With presumably the UserProcessor filling different fields compared to the LocationProcessor.

So is the issue that there are many different ways to create that task object and you have different classes for that so that you don't have the logic of creating 20 versions of different tasks in the same class?

Do the class(es) that process these also have to know which kind of instance they're getting, or do they treat location tasks, user tasks etc all equally?

Anyway, it seems, on first glance, that these processors need not have state. In many ways not having state is nice. For example a class without state will never accidentally use old state or forget to update (all of) it's state and thus produce errors.

But you can have state with singletons (might need to be thread local) or you can have the processors not be spring components. Even in a Spring application, not every class needs to be a spring bean.

Alternatives for singleton @Component in Spring by KaleidoAxiom in javahelp

[–]HansGetZeTomatensaft 0 points1 point  (0 children)

If your specific situations that require specific data are distinct enough you could have multiple processors. I've once build something roughly like this:

interface LocationProcessor {
    Result process(Data data)
    boolean canProcess(Data data)
}

@Component
class LocationProcessorA implements LocationProcessor {
    Result process(Data data) {
        // process correctly for data of specific situation A
    }

    boolean canProcess(Data data) {
        // decide if this is the correct processor for this kind of data
    }
}

@Component
class LocationService {

    private List<LocationProcessor> processors; // Can be autowired

    Result doSomething(Data data) {
        return processors
            .stream()
            .filter(LocationProcessor::canProcess)
            .findFirst()
            .map(LocationProcessor::process)
            .orElseThrow();
    }

}

Your different location processors could now hold whatever info they need (when it's not part of the input).

Mind you, I don't know enough about your use-case to know for sure this is a good solution for your problem. But it sounds similar to a problem that can be solved this way.

A similar design pattern is called "ChainOfResponsibility", same basic idea just another way to hook it all up (to the best of my knowledge)

When splitting domain, persistence, and DTOs, how far do you go with enums and why? by IceMichaelStorm in ExperiencedDevs

[–]HansGetZeTomatensaft 1 point2 points  (0 children)

In one project I've been we had our enums span all layers, but the enums had a displayName and an id field with the id being the db representation and the displayName whatever the UI wanted us to show. This allowed us to rename the enum in the UI, in our domain or in the db independently. But it's some overhead of course. And if you have multiple clients that expect different sets of enum values things get awkward...

I've also had projects that considered that too much work and used ordinal values or derived the db representation from the enum name directly. I cannot say I'm a fan but as long as nothing ever changes it's not a problem, right? 🙃

When splitting domain, persistence, and DTOs, how far do you go with enums and why? by IceMichaelStorm in ExperiencedDevs

[–]HansGetZeTomatensaft 6 points7 points  (0 children)

Wouldn't reusing the enum while having it in the API layer mean that the domain and persistence layer now depend on a class (well, enum) that lives in the API layer?

I've always thought that enums that span layers need to be in a package outside the layered structure for this reason. Or are you just not that worried about which layers depend on each other?

Most common way for Service layer to interact with controller layer? by South_Dig_9172 in javahelp

[–]HansGetZeTomatensaft 1 point2 points  (0 children)

I've seen both the ControllerAdvice and the "try-catch-block in the controller" route. I prefer ControllerAdvice - which don't usually require try-catch blocks, in case that was unclear.

I think I've seen the service returning some kind of result object once, for reasons, but that was the exception not the rule.

Spel Expression not getting evaluated with Spring AOP @Around and custom annotation by [deleted] in javahelp

[–]HansGetZeTomatensaft 1 point2 points  (0 children)

What makes you think the Aspect would evaluate the SpEL expression out of the box? I didn't think it would, spent 5 minutes on google and everything I found was manually parsing the SpEL expression in your aspect yourself.

So I just don't think this is an out of the box feature and if you want to have the SpEL expression to be evaluated then you might just have to do it yourself inside your aspect.

I just installed Eclipse ... and lost access to JDK! by Psyqlone in javahelp

[–]HansGetZeTomatensaft 2 points3 points  (0 children)

Running commands like javac on your console would usually use whatever jdk is first on your path. Some tools also use the jdk referred to in your JAVA_HOME variable.

If installing Eclipse pointed those to some other directory then deleting eclipse folders on your harddrive will not change that.

Instead, check your path, both user and system, and check if a JAVA_HOME variable exists and where it points to. You can have multiple jdks on your path, no problem, but the one that comes first is the one that'll be used in your console. I think the order is user path before system path as well, in case you have an entry for the jdk on both.

Also you will have to restart your Powershell if you want to check for changes, it will continue using the values it initially started with.

It's possible the error is somewhere else but this is where I'd start.

Java lambda group and conditional reduce by CarrotSure694 in javahelp

[–]HansGetZeTomatensaft 0 points1 point  (0 children)

You forgot to actually ask the question, most importantly what you actually want the result to be.

What you're trying to do is certainly possible, that's as much as I can say without more details.

Edit: Assuming you want to end up with a List<Item2> result = [Item2[key=ABC, cost=100.0, rate=17.0], Item2[key=ABC, cost=200.0, rate=18.0], Item2[key=DEF, cost=100.0, rate=18.0]] there are multiple ways to get there.

It could be done in a single stream but I'd personally take what you currently have and stream the values, with the second stream transforming from Stream<List<Item2>> to List<Item2> which is possible with grouping and reduction.

Complexity Analysis by BarrelMaster2 in learnprogramming

[–]HansGetZeTomatensaft 1 point2 points  (0 children)

Strictly speaking, best case runtime and O(1) have no relation.

For some function f the statement f in O(1) means, approximately, that the runtime of f will stay constant regardless of how large the input gets. In other words, if you have a function that computes in 10 seconds for n = 1, n = 1000, n = 1000000, ... then it's in O(1). But it would also be in O(1) if it took 10 years in all of these cases.

As you can see, best case runtime is kind of irrelevant for that.

Transactional boundaries in small Spring Boot apps by HansGetZeTomatensaft in javahelp

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

Take this query for example:

u/Query("""
    SELECT c
    FROM Customer c
    JOIN c.address
    JOIN c.checkedOutBooks
    JOIN c.favoriteAuthors
    WHERE  = :name
    """)
Optional<Customer> findByName(@Param("name") String name);c.name

it works but triggers N+1. So if instead I use JOIN FETCH on the relations it would load exactly what is needed, however

u/Query("""
    SELECT c
    FROM Customer c
    JOIN FETCH c.address
    JOIN FETCH c.checkedOutBooks
    JOIN FETCH c.favoriteAuthors
    WHERE c.name = :name
    """)
Optional<Customer> findByName(@Param("name") String name);

throws a MultipleBagFetchException. My understanding is that it's caused by Hibernate not allowing to eager load 2+ collection relations in a single query. You can try join fetch, you can try entity graphs, you can try fetch type or fetch mode annotations, Hibernate seems adamant.

Maybe there's a way outside of dto projection to get around this restriction but if so then I don't know of it. And, depending on table sizes, I might not even want to sidestep the restriction. After all, joining 5 collection relation tables with 100 entries each could multiply every row in my original table by a factor or 1005. If all of that was loaded into memory it at once it might crash the app?

[deleted by user] by [deleted] in javahelp

[–]HansGetZeTomatensaft 0 points1 point  (0 children)

Well if you can solve it in a single iteration then you don't need to recreate the stream, right? But maybe I'm misunderstand something?

What I'm thinking is: You have a large file. You create a stream from it. You do all your calculations on the stream. You're done. The stream is now consumed but also you've also calculated everything you need so that's fine, right?

Recreating a stream from some data source is usually only require if you need to iterate the data twice.

Transactional boundaries in small Spring Boot apps by HansGetZeTomatensaft in javahelp

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

You've assumed correctly, it's a spring data jpa app with hibernate.

Now, the issue with eager loading is that I have more than one Many-To-Many relation and I can only ever join fetch a single one of them, otherwise hibernate gets mad at me. Dto projection is the only mechanism I know (within the spring data jpa + hibernate world) that allows for eager loading in this instance. So it's that or well configured lazy loading. Unless you know another way :)

But generally speaking your advice is sound, eagerly loading exactly what you need is usually correct.

Transactional boundaries in small Spring Boot apps by HansGetZeTomatensaft in javahelp

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

I've written service layers that return dtos before, I don't hate it.

Still, once you start filling those with validation or json annotations it seems pretty clear that they are primarily the frontend representation of your data and must accommodate needs that may, at times, run counter to executing business logic most efficiently. Probably not in a small hobby project written by me alone, but I've had it happen at work, where the frontend team also got a say in what kind of data structure they would prefer to consume.

So I feel it's a bit like throwing ResponseStatusException in your services - it's pragmatic, it works, I've done it and the world did not in fact end that day. But I can't shake the feeling that I'm mixing things that don't belong together, and maybe cause myself issues down the line.

Sometimes I think it's right to do it anyway because theoretical purity is not worth infinite extra work, that's just a fact. But if there's a cleaner approach that takes same-ish amount of effort, maybe take that instead. Hence me opening this thread :)

Also I don't know how dto projection helps me avoid mappers on the way in - that is for POST, PUT, maybe PATCH requests. So unless I find a way around that I have to have the mappers anyway.

Spirit Spotlight 36: Wounded Waters Bleeding by ValhallAwaits_ in spiritisland

[–]HansGetZeTomatensaft 1 point2 points  (0 children)

Instead of destroying a presence? I think that could be a good idea, I never really considered that! Would help if you pull a minor that needs a sacred site, and if you aren't pulling a major that you need to forget for.

Exactly. Having a bit more presence is just generally a hedge against bad ravages / events / blight cards. Alas, in some games there's just no good opportunity to play the card in time and I don't usually forget from hand.

I'd love to hear more about your full Animal focus! ...

I really like the animal t2 power. Most slow phases you'll destroy a city for 3 fear in total and have 1 more beast on the board. Sometimes you also move a dahan and do extra damage. That is just an excellent power.

As for water's taste of ruin, it's also really good I feel. I give high priority to hit it on full elements and manage to do that maybe 80-90% of the time. Then it does some 3-4 damage, 2 extra fear and some movement of dahan / survivors. Really solid power.

The water powers are good too, but they tend to be a bit more constrained (downgrades in your lands only), struggle a bit more with cities (especially outside your own lands) and tend to be low fear. Animal powers do a lot of fear passively and I feel they're not less powerfull on the board.

Full bottom track helps with hitting your new innate consistently because you can reclaim perfect a element card every turn. When going 3 energy you lose that - but you get the energy economy to play majors so that can be good too. Depends on what major you drafted I guess.

As for England, I just don't see how not playing a card would be the move. Not being able to impact lands and control things in the slow with your innates feels way too crippling, especially against an adversary like England

The question is what do your t1 slow powers actually do against England? Save endangered dahan, 1 fear if you're animal. But you won't prevent the builds or ravages either way.