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
Zorro KingOfEngland
May 7, 2008

BabyFur Denny posted:

One of the many reasons why spark is such a terribly lovely framework

I'm in the process of learning Spark right now. Is there a better alternative I should be looking at?

Adbot
ADBOT LOVES YOU

Volguus
Mar 3, 2009

Zorro KingOfEngland posted:

I'm in the process of learning Spark right now. Is there a better alternative I should be looking at?

geeves posted:

Look into Jersey https://jersey.java.net or Spring Boot with REST https://spring.io/guides/gs/rest-service/ (We use the former in production and for a brand new API looking into the latter.

Good Will Hrunting
Oct 8, 2012

I changed my mind.
I'm not sorry.
lol Jersey and Spring are not alternatives to Spark, but drinking a gallon of bleach is

BabyFur Denny
Mar 18, 2003

Zorro KingOfEngland posted:

I'm in the process of learning Spark right now. Is there a better alternative I should be looking at?

It depends on what you actually want to do because nowadays spark is used for all kind of stuff that it should never be used for.

Volguus
Mar 3, 2009

Good Will Hrunting posted:

lol Jersey and Spring are not alternatives to Spark, but drinking a gallon of bleach is

http://sparkjava.com/

Looks like that to me.

Good Will Hrunting
Oct 8, 2012

I changed my mind.
I'm not sorry.

Volguus posted:

http://sparkjava.com/

Looks like that to me.

Different Spark my friend, he means Apache Spark I'm guessing.

John F Bennett
Jan 30, 2013

I always wear my wedding ring. It's my trademark.

Wait, we're not talking about Spark the Java framework, right? Because I thought that was a good choice if you need a light framework.

Also, which ORM is all the rage these days? I used to use Hibernate when I was creating Spring applications but that was a few years ago and I'm not really into enterprise dev anymore these days.

John F Bennett fucked around with this message at 21:09 on Mar 21, 2017

Volguus
Mar 3, 2009

Good Will Hrunting posted:

Different Spark my friend, he means Apache Spark I'm guessing.

Well, he could be talking about Spark the Bleach (the gallon model) for all I can tell.


John F Bennett posted:

Wait, we're not talking about the Spark the Java framework, right? Because I thought that was a good choice if you need a light framework.

Also, which ORM is all the rage these days? I used to use Hibernate when I was creating Spring applications but that was a few years ago and I'm not really into enterprise dev anymore these days.

The author of the post did not specify which Spark he's talking about, so everyone (including me) had a different idea. Someone is wrong, someone will be right. As for Spark the web framework being a good choice ... it may be, he asked for alternatives, Spring Boot Web is one.

ORMs : Hibernate is the most mature of them all. Could/should go with JPA, for an yet another abstraction layer over Hibernate, and could go with Spring Data to make it even easier to work with the entities.

Volguus fucked around with this message at 21:10 on Mar 21, 2017

BabyFur Denny
Mar 18, 2003
I thought with the previous posts it would be quite clear what Spark we're talking about

Zorro KingOfEngland
May 7, 2008

I was talking about Apache Spark (gallon of bleach edition), not the web framework which is also called Spark.

BabyFur Denny posted:

It depends on what you actually want to do because nowadays spark is used for all kind of stuff that it should never be used for.

I'm trying to learn what not to do before I've already started using it in a production setting. I can certainly see how it could be misused but do you have any concrete examples you can share?

Tactical Shitpost
Jun 13, 2016

John F Bennett posted:

Also, which ORM is all the rage these days? I used to use Hibernate when I was creating Spring applications but that was a few years ago and I'm not really into enterprise dev anymore these days.

Hibernate is the "enterprisey" one, but if you want something smaller that acts as a library and not a full blown framework check out MyBatis. Compared to Hibernate MyBatis is IMO easier to use if you want to write your own SQL, need to work with already existing table structure or need to use fancy database-specific features.

Tactical Shitpost
Jun 13, 2016
By the way, IntelliJ IDEA 2017.1 was released

https://www.jetbrains.com/idea/whatsnew/

PierreTheMime
Dec 9, 2004

Hero of hormagaunts everywhere!
Buglord
I have a hopefully simple and likely dumb question: is there any way to pare down the file size of including POI in your build path? Does it really take 11+MB to write an xlsx file?

I mean it's all working fine it's just a huge .jar for a fairly basic process.

geeves
Sep 16, 2004

Tactical Shitpost posted:

By the way, IntelliJ IDEA 2017.1 was released

https://www.jetbrains.com/idea/whatsnew/


Does not deliver.




At least there's emojicode.

HFX
Nov 29, 2004

geeves posted:

Does not deliver.




At least there's emojicode.

Emoji is neither a valid return type or a valid character for identifiers.

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...

PierreTheMime posted:

I have a hopefully simple and likely dumb question: is there any way to pare down the file size of including POI in your build path? Does it really take 11+MB to write an xlsx file?

I mean it's all working fine it's just a huge .jar for a fairly basic process.

You can use proguard to strip out unused classes without obfuscating anything or using other protection features.

poemdexter
Feb 18, 2005

Hooray Indie Games!

College Slice

HFX posted:

Emoji is neither a valid return type or a valid character for identifiers.

Well there goes my plan to have all my packages named poop emoji.

Tactical Shitpost
Jun 13, 2016

poemdexter posted:

Well there goes my plan to have all my packages named poop emoji.

You might get a chuckle or two out of this library https://github.com/stokito/gag

PierreTheMime
Dec 9, 2004

Hero of hormagaunts everywhere!
Buglord
Is getting Maven to work with Eclipse on Windows typically a miserable experience or am I just terrible at this? I managed to get the absolutely basic install working and creating default builds, but I cannot for the life of me get it functioning within Eclipse, either creating new projects from within the IDE or importing the test projects.

I'm sure it's a matter of buckling down and getting all my settings correct but I just want to get started on a web project and this agonizing process is really draining my enthusiasm. :(

FateFree
Nov 14, 2003

If I were you I would just download Eclipse STS and everything works out of the box. You shouldn't need to install maven as a separate application or anything. I'm sure thats the same for other versions of eclipse as well.

The flow should be something like.. unzip Eclipse STS, start a new maven project, edit the pom to add some dependencies maybe and thats it. Maven is just really a folder on your hard drive that has a settings file and all your local dependencies, everything else that runs it is built into eclipse.

FateFree fucked around with this message at 04:10 on Mar 29, 2017

geeves
Sep 16, 2004

I've never had to write a custom deserializer for Jackson + Jersey before. But at some point with maven-izing somewhere in the JaxRS / Jackson / Jersey line, Long millis stopped being accepted as a valid conversion to Date. Nearly every example of a JsonDeserializer is the same, however it doesn't seem to be working. I have confirmed that the debugger can see all of the other setters for things like "name", "subject", but even with the deserializer annotation on the setter for Date, it's completely skipped.

I've tried to get as much logging from the libraries as possible, but there are no messages displayed when I add com.fasterxml, etc. to log4j.

I haven't tried sending a formatted date string, but I'll probably run into similar issues.

I don't think it's a codehaus vs fasterxml issue as some libs have codehaus dependencies (the class path is different).

Has anyone had similar issues?

code:
public class JsonDateDeserializer extends StdDeserializer<Date> { // have also tried JsonDeserializer<Date>
    private static Logger log = Logger.getLogger(JsonDateDeserializer.class);

    public JsonDateDeserializer() {
        this(null);
    }

    public JsonDateDeserializer(Class<Date> date) {
        super(date);
    }

    @Override
    public Date deserialize(JsonParser jsonparser, DeserializationContext context) throws IOException {
        log.info("Deserialize. value: " + jsonparser.getLongValue());
        try {
            return new Date(jsonparser.getLongValue());
        } catch (IOException e) {
            log.error(e.getMessage(), e);
        }
        return null; // don't worry about null for now...
    }

}

@JsonDeserialize(using = JsonDateDeserializer.class)
public void setStartDate(Date startDate) {
    this.startDate = startDate;
}

Tactical Shitpost
Jun 13, 2016

geeves posted:

I've never had to write a custom deserializer for Jackson + Jersey before. But at some point with maven-izing somewhere in the JaxRS / Jackson / Jersey line, Long millis stopped being accepted as a valid conversion to Date. Nearly every example of a JsonDeserializer is the same, however it doesn't seem to be working. I have confirmed that the debugger can see all of the other setters for things like "name", "subject", but even with the deserializer annotation on the setter for Date, it's completely skipped.

I've tried to get as much logging from the libraries as possible, but there are no messages displayed when I add com.fasterxml, etc. to log4j.

I haven't tried sending a formatted date string, but I'll probably run into similar issues.

I don't think it's a codehaus vs fasterxml issue as some libs have codehaus dependencies (the class path is different).

Has anyone had similar issues?
Have you weeded out stupid mistakes like the deserializer using java.sql.Date and the pojo using java.util.Date? Do you have jackson-databind in the class path (or some of these if you are using something fancy)? Which (de-)serializer features have you enabled (see this and this)?

If it's not one of the above, can you do an one file unit test with the issue and throw it in a github gist?

venutolo
Jun 4, 2003

Dinosaur Gum
At work, we are finally looking at doing some automated integration testing. I think we are looking into what we can use for mocking HTTP services or service virtualization or what the proper nomenclature is. Does anyone have any suggestions for what to use? I ask here rather than the CI/CD thread because I'm interested in stuff a bunch of Java devs can setup/configure/run.

baquerd
Jul 2, 2007

by FactsAreUseless

venutolo posted:

At work, we are finally looking at doing some automated integration testing. I think we are looking into what we can use for mocking HTTP services or service virtualization or what the proper nomenclature is. Does anyone have any suggestions for what to use? I ask here rather than the CI/CD thread because I'm interested in stuff a bunch of Java devs can setup/configure/run.

Wiremock basically.

geeves
Sep 16, 2004

Tactical Shitpost posted:

Have you weeded out stupid mistakes like the deserializer using java.sql.Date and the pojo using java.util.Date? Do you have jackson-databind in the class path (or some of these if you are using something fancy)? Which (de-)serializer features have you enabled (see this and this)?

If it's not one of the above, can you do an one file unit test with the issue and throw it in a github gist?

I'll check those tomorrow. The short answer is none. We haven't had to before because they just worked (our old build was just grabbing a lib directory full of jars and throwing it in root.war). I'll double check the classpath, but I'm pretty certain it's there and it also is in mvn dependency:tree.

Do I have to register them in my class that initially extends ResourceConfig? The deserialize method doesn't seem to be called as breakpoints aren't recognized in the method and log.info() doesn't output anything to our log file (neither does System.out)

I'll admit it has been blind luck that these have worked as they have for as long as they have.

I might try deserializing the entire class instead of just the affected field.

Le0
Mar 18, 2009

Rotten investigator!
I'd like to make a list of superclass and store them in a single list. Then get them out and do stuff with them.
One way would be to use instanceOf, but I read everywhere that's it bad practice (is it really?) and should be avoided. The thing is that I don't really see how I could do what I want without it because I cannot have just a single method I think, my subclass have different attributes etc.. I'd like to get/set independently.

code:
public class SuperClass {}
public class Class1 extends Superclass {}
public class Class2 extends Superclass {}

ArrayList<SuperClass> myItems;

for (SuperClass myItem: myItems) {
    if (myItem instanceof Class1) {
        Class1 subClass = (Class1) superClass;
    }
    else if (myItem instanceof Class2) {
        Class2 subClass = (Class2) superClass;
    }
}

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...
I don't know why someone told you not to use instanceof.

I also don't really know what your end goal is, so what you posted seems fine?

Le0
Mar 18, 2009

Rotten investigator!

Volmarias posted:

I don't know why someone told you not to use instanceof.

I also don't really know what your end goal is, so what you posted seems fine?

I mean, I'm a total newbie on Java, I just researched on the net and you get quite a few people saying that usually it's a sign of badly designed class and that you usually can fill your needs by overriding a method or something.
Honestly I just wanted to ask more knowledgable persons than me.

What I'm trying to do would be something similar to an inventory of items.
I have an base item class which all item inherit. But then I have like a potion which can have an effect or something, and a weapon which has attack etc... but everything is stored in the same inventory list.

Le0 fucked around with this message at 14:52 on Mar 31, 2017

geeves
Sep 16, 2004

Le0 posted:

I mean, I'm a total newbie on Java, I just researched on the net and you get quite a few people saying that usually it's a sign of badly designed class and that you usually can fill your needs by overriding a method or something.
Honestly I just wanted to ask more knowledgable persons than me.

What I'm trying to do would be something similar to an inventory of items.
I have an base item class which all item inherit. But then I have like a potion which can have an effect or something, and a weapon which has attack etc... but everything is stored in the same inventory list.

It's to avoid bad design decisions where class1 does one thing and class2 does another. This is a short and good example of misusing instanceof and where it can lead to headaches later down the line: http://www.javapractices.com/topic/TopicAction.do?Id=31

It's not avoiding instanceof all together, it's more to encourage polymorphism. Google "instanceof vs polymorphism" and you'll have some solid stackoverflow answers. Don't worry if you don't get polymorphism right away, it's one of those things that may take a bit to click.

Jo
Jan 24, 2005

:allears:
Soiled Meat

Zorro KingOfEngland posted:

I was talking about Apache Spark (gallon of bleach edition), not the web framework which is also called Spark.


I'm trying to learn what not to do before I've already started using it in a production setting. I can certainly see how it could be misused but do you have any concrete examples you can share?

gently caress I hate Apache Spark. If there's an alternative to that and drinking bleach I'd like to lean on it. I had to bail after a month of work on it because I couldn't avoid the unstated performance gotchas.

Be advised: if you read from a gz file, all your code will run serially. Be sure your data is bz2 or a bunch of gz files.

Be advised that the default number of data partitions is two. If you're running out of memory for no GODDAMN reason, that's it.

Keep an eye open at startup for your monitor port. You can connect via HTTP to get nice visualizations and progress updates.

Good Will Hrunting
Oct 8, 2012

I changed my mind.
I'm not sorry.

Jo posted:

Be advised: if you read from a gz file, all your code will run serially. Be sure your data is bz2 or a bunch of gz files.

Could you elaborate on this a bit? Interesting (and possibly important) to me.

BabyFur Denny
Mar 18, 2003

Good Will Hrunting posted:

Could you elaborate on this a bit? Interesting (and possibly important) to me.

well gzip is not splittable, so you can't have tasks just start reading somewhere from the middle of the file and be able to decompress it. You always need to read the whole file from beginning to the end. This basically kills any attempt to parallelise things.

bz2 is splittable so you can have several tasks share the work. Same if you have several gzip files, obviously.

Bob Morales
Aug 18, 2006


Just wear the fucking mask, Bob

I don't care how many people I probably infected with COVID-19 while refusing to wear a mask, my comfort is far more important than the health and safety of everyone around me!

Good Will Hrunting posted:

Could you elaborate on this a bit? Interesting (and possibly important) to me.

You might find this link interesting - it talks about some of those details and has a link to pigz which is a parallelized gzip

https://news.ycombinator.com/item?id=12327905

baka kaba
Jul 19, 2003

PLEASE ASK ME, THE SELF-PROFESSED NO #1 PAUL CATTERMOLE FAN IN THE SOMETHING AWFUL S-CLUB 7 MEGATHREAD, TO NAME A SINGLE SONG BY HIS EXCELLENT NU-METAL SIDE PROJECT, SKUA, AND IF I CAN'T PLEASE TELL ME TO
EAT SHIT

That's a good name. QtPy is still the best though

Jo
Jan 24, 2005

:allears:
Soiled Meat

Good Will Hrunting posted:

Could you elaborate on this a bit? Interesting (and possibly important) to me.

Others have replied already, but it's worth providing my anecdote:

Gzip, roughly, is streaming. To decode the n-th byte you need to decode the 0th through n-1. BZip allows you to decompress the nth byte without decoding everything before it.

I had an 11TB gzip file and couldn't figure out why spark was only using one core. It was reading, linearly, through the whole file. I switched to bz2 and that allowed more than one core to work at the same time.

Our overseas team used gz, too, but they split it into a bunch of smaller gz files.

Volguus
Mar 3, 2009

Le0 posted:

I'd like to make a list of superclass and store them in a single list. Then get them out and do stuff with them.
One way would be to use instanceOf, but I read everywhere that's it bad practice (is it really?) and should be avoided. The thing is that I don't really see how I could do what I want without it because I cannot have just a single method I think, my subclass have different attributes etc.. I'd like to get/set independently.

code:
public class SuperClass {}
public class Class1 extends Superclass {}
public class Class2 extends Superclass {}

ArrayList<SuperClass> myItems;

for (SuperClass myItem: myItems) {
    if (myItem instanceof Class1) {
        Class1 subClass = (Class1) superClass;
    }
    else if (myItem instanceof Class2) {
        Class2 subClass = (Class2) superClass;
    }
}

You could look into using the visitor pattern (the first thing that comes to mind when seeing instanceof). The pattern itself is not without its issues, but usually it beats having a bunch of instanceof's.

venutolo
Jun 4, 2003

Dinosaur Gum
At work we have a couple of junior devs that my boss has asked me to work with to improve their code (ugh). One has been with us for about 18 months and straight out of college (BS in CS). The other had worked for the company for a number of years, took a couple online Java courses, and has been on the engineering team for what I'd guess is three years or so.

I have not seen either's work in a very long time since they've been a part of a different engineering sub-team (7 engineers, 2 sub-teams of 3 plus a really senior guy who basically works on his own). So I'm not sure what the specific problems with each are, but I'd guess they have poorly designed code, poor practices (if any), and are not good with their tools/environment/etc (IDE, debugger, Git, Spring, Maven).

Does anyone have experience with how to get junior guys up to speed or how to approach this?

My best guess at this point is as follows. Have them read a chapter of Clean Code every day and discuss it with them. After that, collectively do a project with them that would be the kind of thing that I could knock out in two or three days on my own, and go through the whole process explaining everything I do and the why of it. And then maybe do another similar project where I don't write any code or do design, but guide them, be very interrogative about every design choice, and be very harsh in reviewing the project on a daily basis until the project was something I'd be okay considering being attributed to me in some way.

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...
Code reviews too.

Good Will Hrunting
Oct 8, 2012

I changed my mind.
I'm not sorry.
You could try thinking about what you would have wanted when you were at their level and asking them if they feel like it fits their learning style. Everyone is different after all.

Adbot
ADBOT LOVES YOU

venutolo
Jun 4, 2003

Dinosaur Gum

Volmarias posted:

Code reviews too.

Yeah, we do code reviews, but I've not been on their reviews in the past as reviews are done by members of the same sub-team. I plan do to daily reviews of their code sitting next to them and being very strict about what I will approve.

Good Will Hrunting posted:

You could try thinking about what you would have wanted when you were at their level and asking them if they feel like it fits their learning style. Everyone is different after all.

Yeah, I plan to ask them what they need help with and how they think they would learn best. I have a bit of trouble putting myself in their shoes because at the same point my career I was very interested and motivated to get better and worked lot on my own to develop good practices and design. There was basically nobody around to help me, so I was forced to figure it all out myself, which I was actually fine with because I learn well like that. Basically what I wanted would have been good resources (books, etc) and to be left alone to sink or swim.

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