Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
smackfu
Jun 7, 2004

Any opinions of Project Lombok? It uses annotations to replace boilerplate like getters and setters and isequals. Which is neat, but you end up with Java code that doesn't compile unless you are using a supported tool chain and IDE which weirds me out.

https://projectlombok.org/features/

Adbot
ADBOT LOVES YOU

smackfu
Jun 7, 2004

To tie the two subjects together, Effective Java is really good at explaining where all that boilerplate code comes from, and why it takes 20 lines to write a proper equals or hashcode method.

Too bad it only goes up to Java 6 so I imagine some of the advice is not current best practices. Also IIRC some of the suggestions don't play well with unit testing, like singletons.

smackfu
Jun 7, 2004

I'm new to Maven/Jenkins and have a question about release versions, namely when do people perform non-SNAPSHOT releases?

Option 1: Perform a release every time we deploy a test build. Testers find a bug in a particular release and then it is fixed in a subsequent one, and we just deploy the last release that the testers sign off on without rebuilding.

Option 2: Testers test on SNAPSHOT versions and we only perform a release after they sign off. So one release per production deployment.

if it matters, our SNAPSHOT builds are triggered in Jenkins after a commit, but deployment is still manual even to test systems.

smackfu
Jun 7, 2004

Like using the subversion revision number of the last snapshot build to check out for the release version?

smackfu
Jun 7, 2004

Maybe something like Test Driven Development by Example would be useful?
http://www.amazon.com/Test-Driven-Development-By-Example/dp/0321146530

JUnit as such is a pretty shallow subject in my opinion, but writing good tests or using mocking is where the complexity comes in.

smackfu
Jun 7, 2004

People writing tests for getters and setters are usually trying to get 100% test coverage in my experience.

smackfu
Jun 7, 2004

TheresaJayne posted:

Gradle is faster than Maven, I wish we didnt need to use Maven at work,

Our Maven Build has 320 projects and takes 90 minutes to build and test.
The same project under Gradle is 312 projects and 15 minutes to build and test.

The extra projects in Maven are the bundle poms and the master poms that we have in the master gradle build.gradle as tasks.

Why would Gradle be faster than Maven? Aren't they both just running other programs (compiler, test runners) which is most of the build / test time?

smackfu
Jun 7, 2004

Yeah, I mean, it's Spring Boot, the whole idea is that it should work without config in as many cases as possible. The memory settings were probably chosen fairly arbitrarily but high so that most apps work without getting an out-of-memory error.

smackfu
Jun 7, 2004

Wheany posted:

Well, on a TDD course I took, this is exactly what the instructor did, with a more trivial example:

...

"Whoops, that didn't work, apparently it's 3"
Java code:
// test code
assertEquals(3, sum(1, 2));
"That turned the test green, let's move on"

Um, isn't this a bit backwards if you are calling it TDD? You are supposed to change the code to make the test green, not the test. So the test should always say 3 (when you write it first), but the sum() method might have originally just returned the constant 3 instead of a+b.

smackfu fucked around with this message at 11:55 on Apr 27, 2016

smackfu
Jun 7, 2004

Just use IntelliJ, it tries really hard to name things correctly.

smackfu
Jun 7, 2004

If some of the constants are calculated, they don't need to be constants and you can use a method instead.

Like the 8 ,16, 24 values.

smackfu
Jun 7, 2004

So you want to do this without changing the code, just the log config? Seems like it should be possible. One of the parameters for the log format string is "nested diagnostic context" which seems like the stack trace.

http://logback.qos.ch/manual/layouts.html

Edit: too complex to figure out the details while phone posting.

smackfu fucked around with this message at 13:21 on May 23, 2016

smackfu
Jun 7, 2004

Wheany posted:

So how do you make a gui in a desktop java application in the space year 2016?

Still Swing?

I probably want it to be cross-platform, but I'm going to develop it on Windows.

Run a web server on a local port.

smackfu
Jun 7, 2004

One good reason to have unit tests is so you can refactor and know that things still work.

smackfu
Jun 7, 2004

I have a Product class. I also have a List<Product> that contains all the products that belong to someone. I have some methods that operate on the list.

Why would it be a bad idea to create a new ProductList class that extends List<Product> and put the methods in that object, instead of the controller? It feels like not a common pattern in Java but I'm not sure why.

Edit: I think I see why I am getting messed up. Normally you would have a User object and that would contain (not extends) the List of Products and you would have methods on the User. In this case I just have the free floating list. So I probably should just create a User to make it a proper domain model.

smackfu fucked around with this message at 21:41 on Jul 1, 2016

smackfu
Jun 7, 2004

Whatever Effective Java says to do. Don't have my copy handy but it's super useful for this kind of question.

smackfu
Jun 7, 2004

When do you change the value of temp?

And don't call variables "temp".

smackfu
Jun 7, 2004

Why would you roll your own DAOs?

smackfu
Jun 7, 2004

The parent of FileWriter is OutputStreamWriter, whose documentation says:

quote:

Each invocation of a write() method causes the encoding converter to be invoked on the given character(s). The resulting bytes are accumulated in a buffer before being written to the underlying output stream.

Given that, the documentation is pretty lacking in those classes. Like flush() is documented as "Flushes the stream" which requires you already know what flushing means. I guess the problem is that these are methods on abstract parent classes, so they have to be documented abstractly, and then they aren't documented at all on the concrete class like FileWriter, where the description of flush() would be "Writes the buffer to disk."

smackfu fucked around with this message at 18:38 on Oct 12, 2016

smackfu
Jun 7, 2004

If I want to do an action 5 times, is there a fancier way in modern Java than an old school for loop?

smackfu
Jun 7, 2004

Has anyone had any luck slowly updating a legacy code base to newer technologies? The old code has SQL mixed in with controllers all over the place. It's pretty easy to pull out repositories and modes and such but it would be nice to stick in Hibernate and some kind of dependency injection framework but without breaking all the other existing code that we aren't touching yet.

smackfu
Jun 7, 2004

Does anyone know why the heck property files aren't UTF-8 encoded by default? Just seems weird considering the rest of Java.

smackfu
Jun 7, 2004

I have a bit of a general best practices question...

I have two model objects, a Department and an Employee. Each one is persisted in a different database table. The employee table has a department id.

How should the Employee object represent the department? It seems like it should have a Department object, but instantiating a Department requires me to also query the department table. This seems like it could easily get out of hand if there are a lot of related tables. OTOH, I could have the department id as an attribute of the Employee, and a getDepartment() method to retrieve the full object (with some caching), but that seems to be introducing implementation details into my models.

How does Hibernate/JPA deal with this?

smackfu
Jun 7, 2004

So Employee has both department_id (always present) and department (null until accessed) fields? I guess that's what is tripping me up.

smackfu
Jun 7, 2004

You don't need a single source of truth for the ID which can be useful in distributed contexts.

smackfu
Jun 7, 2004

Apparently if you have a one-to-one Hibernate relationship, and you define it as lazy, it doesn't actually make it lazy. Because there is no way to give you a pointer that might need to be null if the other side of the relationship doesn't exist. (I think that's the reason.) So every time you fetch the parent, it fetches the child in a separate query.

I feel like that deserves a warning or something. And there's no easy fix to it either.

smackfu
Jun 7, 2004

Use Maven and don't think about it?

smackfu
Jun 7, 2004

Aren't you essentially calling format twice?

efb

smackfu
Jun 7, 2004

Your legal department probably doesn't want you to use that weird Sun junk anyways.

smackfu
Jun 7, 2004

Ask, the libraries that rely on older versions of the dependencies might not even work properly with the new one, even if you get it set to only use the new one. So that's fun.

smackfu
Jun 7, 2004

Anyone use any neat Spring things with Spring Boot? They have what seems like dozens of packages, are there any that you found particularly useful?

smackfu
Jun 7, 2004

I will need to try that. I've been playing with the SpringFox Swagger package which auto documents your REST apis. It's useful for seeing which end points you were lazy with, like "why is DELETE enabled on this controller???" And useful if someone says that you need to document APIs of course.

Spring Actuator is also really cool although I'm not sure how to use it in our production environment since our individual web servers are not directly addressable. So you could get stats/health for the server you happen to be connected to but not sure how useful that is.

smackfu
Jun 7, 2004

In my further research, I also found out that Spring Boot Admin exists so you can run that as a separate app and it sits somewhere it can talk to all your web servers and presents a common web interface. Haven't played with it yet but it sounds promising.

As far as dev ops, our problem is that we really only have devs and server-level ops (like alerts get raised if the server CPU goes too high.) App ops (like endpoint errors or slow response times) ends up falling into limbo and then they complain to the devs when users report problems. Dysfunctional!

smackfu
Jun 7, 2004

It should be Baseball, not BaseBall.

smackfu
Jun 7, 2004

It makes me sad how much time students spend on classpath issues.

smackfu
Jun 7, 2004

Surefire has an impressive lack of output options.

smackfu
Jun 7, 2004

M31 posted:

The primitive is autoboxed to a Long object during compilation, so both will be references.

Would it have given an error before autoboxing existed?

smackfu
Jun 7, 2004

hooah posted:

IDEA says that the unzipCommand element is not allowed there. Should I just have not used an archetype in the first place? It seems silly to have something provided for use that doesn't work out-of-the-box.

IDEA errors on pom files are not "real" errors, more like warnings. Running it with Maven will show you whether it's an actual problem.

smackfu
Jun 7, 2004

Ideally each artifact would have its own POM. Is the issue that you need to build multiple jars out of the same source repository?

Adbot
ADBOT LOVES YOU

smackfu
Jun 7, 2004

hooah posted:

Since this thing runs in its own JVM, I'm just going to set the JVM's time zone.

Something to watch out for: If you use JodaTime anywhere, it has its own time zone setting. Generally in sync with the JVM one but if you manually update the JVM one...

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply