|
Thanks for the tips! Please do pile on with the abstractions, that's exactly what our professors do. The chess project is over, so I won't be working more on that, but it was interesting to see how little you can get away with in representing two players and the state of the game. We stored FEN strings in the database and the remote player could then fetch that and draw the new board. I can't really see that it would ever grow into 1000s of different queries, but another project might, I'll cross that bridge when I get there. For now though, let's say we have a ConnectionPool, a DBManager and for the sake of simplicity, a MainProgram which does everything else. Are there good reasons for the MainProgram to inject a connection than for the DBManager to "inject itself" by fetching one? I.e. code:
code:
e: and thinking some more, it's pretty obvious that you might want to use different dbs from time to time, maybe based on load, location or which particular function is in use. Ola fucked around with this message at 10:05 on May 21, 2018 |
# ? May 21, 2018 08:26 |
|
|
# ? May 9, 2024 01:33 |
|
It depends on what MainProgram's responsibilities are. Should it be responsible for acquiring Connections and passing them around every time something needs to use one? If so that's fine! But if that's more of an internal consideration for DBManager, it probably makes more sense to keep the connection stuff in there, so you're not mixing logic through a bunch of different classes But you're still calling a static method, on the ConnectionPool class. That's why calling Connection Pool.getConnection inside the DBManager is bad - you've hardwired this link between two classes, they're inseparable. So if you wanted to do all the connection management inside DBManager (so you can just call #store without having to go get a connection to pass in) you'd typically pass in an instance of ConnectionPool, usually when you're constructing the DBManager, and just call #getConnection on that whenever you need one That way you've injected the component it depends on, and it can happily make use of that to ask for connections or whatever. But because you've supplied that object, you're in full control of what it is and what it does - so it's not tied to a particular implementation like when you use static stuff. And of course, you can create a singleton ConnectionPool if that's what you need (say if multiple components all need to use the same pool), you just inject that same instance into everything that has it as a dependency. (This is another thing DI frameworks can manage for you, defining singletons and scopes to automatically create or reuse a thing, which can be handy on more complex projects) So yeah, it's ok for your dependency manager (the thing that's handing out the components) to call static getters and factory methods to get the instances it'll hand out, because it's like the top level, the source, the thing that creates the dependencies instead of being given them. Everything else should be given instances and interact with those specific objects. So you're ok doing ConnectionPool.getConnection() in MainProgram if you're getting Connections to hand out, because that class is acting as your dependency manager, the source of all these things. It's typically easier to stick all that in a separate class(es) though, just so it's all in one place, like a recipe collection I hope that's not too confusing baka kaba fucked around with this message at 18:01 on May 21, 2018 |
# ? May 21, 2018 17:58 |
|
baka kaba posted:I hope that's not too confusing No, that was good, thanks! The idea is ConnectionPool was a singleton and the DBManager static, because the DBManager (a gradually worse name the fewer responsibilities it has) is just SQL boilerplate, set up PreparedStatement, pull stuff out of ResultSet, catch exceptions and return the result. But feeding it different connections means you could query different databases or with different users. One more question if you don't mind, let's say you have a big complex MainProgram (across multiple classes ofc), it might be some business tool that does everything from billing and orders to customer relations to market analysis etc, with the data stored in SQL. That's a whole bunch of different queries. Would you code those queries (the actual string, not the PreparedStatement) in each MainProgram method that calls the DBManager, or would the DBManager have hundreds of ready-made queries in methods like DBManager.addNewEmployee, or would there be some SQL query repository class serving as the manager for that particular dependency?
|
# ? May 21, 2018 18:26 |
|
.
|
# ? May 21, 2018 18:37 |
|
Ola posted:No, that was good, thanks! The idea is ConnectionPool was a singleton and the DBManager static, because the DBManager (a gradually worse name the fewer responsibilities it has) is just SQL boilerplate, set up PreparedStatement, pull stuff out of ResultSet, catch exceptions and return the result. But feeding it different connections means you could query different databases or with different users. If you really insist on having your DBManager with static methods, then it should make its own PreparedStatements and textual SQL queries and only provide methods like "addNewEmployee". But, as I said before, this DBManager can get really big really fast. It will handle employees, and billing, and orders and customers. Too much, in my opinion. EmployeeRepository.save() would be more approrpiate. The DBManager approach is ok when you are very sure that it will stay small as the application is part of is very small. Then no, you don't need to go crazy with repositories and services and whatnot. By small I mean under 500 lines.
|
# ? May 21, 2018 20:46 |
|
Yeah, that's more of an organisational thing. You don't want DBManager becoming some kind of god object with a method for every single "do thing that touches database" operation your entire application performs, and you also don't really want your MainProgram to duplicate every one of those methods, just so it can pass it along internally by calling the DBManager version So it's cool when DBManager is small and you only have a handful of database operations. When it gets bigger it makes more sense to separate out those concerns, so you have a different 'manager' for things like accounts, sales etc. That's where the repository pattern Volguus is talking about is useful - you get an object focused on a specific domain, with only the methods that relate to that It's neat and easy to reason with and change, but it also keeps components separate. Accounts and Employees probably aren't closely related to each other, being able to treat them separately makes it possible to switch one out - for load balancing, using a different data store, testing etc. Having to replace the entire DBManager to change some parts of it is, well... I'm sure you get the idea at this point!
|
# ? May 21, 2018 21:56 |
|
Volguus posted:If you really insist on having your DBManager with static methods, then it should make its own PreparedStatements and textual SQL queries and only provide methods like "addNewEmployee". But, as I said before, this DBManager can get really big really fast. It will handle employees, and billing, and orders and customers. Too much, in my opinion. EmployeeRepository.save() would be more approrpiate. Yeah I see that. So for all the different categories of things you could do, something with employees, something with customers etc, they'd implement their own .save() method. I guess I'll need to look into better ways of building the actual queries as well.
|
# ? May 21, 2018 22:03 |
|
What's the recommended IDE these days? Took a look at the OP and good god this thread is like a decade old. I was just wanting to mess around with libgdx so something quick and easy would be nice.
|
# ? May 22, 2018 22:00 |
|
I like NetBeans, I think most people use IntelliJ.
|
# ? May 22, 2018 22:12 |
Joe Desperado posted:What's the recommended IDE these days? Took a look at the OP and good god this thread is like a decade old. I was just wanting to mess around with libgdx so something quick and easy would be nice. I don't think the IDE recommendations for Java have changed much in the last 10 years I use IntelliJ daily, it is a wonderful IDE. I can't speak to anything specifically about libgdx though. Looks like they have some info though: https://github.com/libgdx/libgdx/wiki/Gradle-and-Intellij-IDEA
|
|
# ? May 22, 2018 22:13 |
|
Another recommendation for IntelliJ. Sometimes it feels like it's the only one with continuing user interface improvements. Has NetBeans had any releases after being transferred to Apache?
|
# ? May 22, 2018 22:15 |
|
Cool. I used to use NetBeans waaay back in the day and haven't touched Java in years. A lot of recs for IntelliJ though so I'll definitely check that out.
|
# ? May 22, 2018 22:55 |
|
IntelliJ has a free version, so you can definitely try it out. If you need the pro features, netbeans and eclipse are better. Simply you can't beat the value proposition. Unless you try them all though, you can't make an informed decision (and sometimes that's fine, to fool around you don't need much).
|
# ? May 23, 2018 01:24 |
|
Joe Desperado posted:What's the recommended IDE these days? Took a look at the OP and good god this thread is like a decade old. I was just wanting to mess around with libgdx so something quick and easy would be nice. Eclipse or IntelliJ
|
# ? May 23, 2018 01:34 |
|
Volguus posted:IntelliJ has a free version, so you can definitely try it out. If you need the pro features, netbeans and eclipse are better. Simply you can't beat the value proposition. Unless you try them all though, you can't make an informed decision (and sometimes that's fine, to fool around you don't need much). I used eclipse for many years before finally coming over to IntelliJ and good gravy is it better and nicer. What are you seeing with Eclipse that IntelliJ doesn't offer?
|
# ? May 23, 2018 02:18 |
|
Volmarias posted:I used eclipse for many years before finally coming over to IntelliJ and good gravy is it better and nicer. What are you seeing with Eclipse that IntelliJ doesn't offer? For me, Java EE support, in the community edition.
|
# ? May 23, 2018 02:21 |
|
Why does this go over the file twice? (I know what I'm doing with the constructor call, this is just getting it working)code:
rice,20 frozen vegetables,40 Is it seeing the comma as meaning theres a new line? The output in the console is correct, apart from being double. underage at the vape shop fucked around with this message at 13:29 on May 23, 2018 |
# ? May 23, 2018 13:25 |
|
underage at the vape shop posted:Why does this go over the file twice? (I know what I'm doing with the constructor call, this is just getting it working) It doesn't. It goes through the file only once.
|
# ? May 23, 2018 13:40 |
|
underage at the vape shop posted:Why does this go over the file twice? (I know what I'm doing with the constructor call, this is just getting it working) It doesn't do that for me. This doesn't seem like it's all the code, so I would say search for another call to parse() in your project. I assume you've already checked the CSV and it isn't doubled in the input?
|
# ? May 23, 2018 13:45 |
|
aaaaaa its because of someone else mistake in a unit test. they fixed it.
|
# ? May 23, 2018 14:03 |
|
So, since Java serialization is being removed at some point (because it is involved in a very large number of java vulnerabilities), what options do I have for type safe (and easy) serialization to disk for my burp and fart hobby app?
|
# ? May 30, 2018 12:23 |
|
Wheany posted:So, since Java serialization is being removed at some point (because it is involved in a very large number of java vulnerabilities), what options do I have for type safe (and easy) serialization to disk for my burp and fart hobby app? Text formats: xml, json, properties Binary formats: protobuf, msgpack, fast buffers Comedy option: make your own If you really hate yourself: yaml
|
# ? May 30, 2018 13:03 |
|
Small question. I have some database from which I pull all the data from this one table (13K records but 150K on disk, some fields have HUGE content) and put it in a List. In the implementation, I need to search this List a zillion times. I am worried this is slow, due to the size, it will kill the nightly batchjob. Should I ramp up the serverspecs this thing is running on or should I be a good boy and just query the server every time?
|
# ? May 30, 2018 15:10 |
|
Does the table data fit into memory if you fetch it all at once? If not, do you HAVE to fetch all of the columns of the table data, or can you fetch most and get the rest as needed? Can your searches map to the list in some way? Would having a Map help? Can your zillion queries be optimized in some way?
|
# ? May 30, 2018 15:17 |
|
That sounds like something you should let the DB handle as long as it's indexed properly. If it has to be done in memory, make some kind of Map structure so you're not searching over and over. Also possibly Streams if it doesn't have to be done in a specific order?
|
# ? May 30, 2018 16:54 |
|
Yeah, gonna take the column I search on and the one I need, put it in a Map and go from there.
|
# ? May 30, 2018 17:53 |
|
Trip report: Mac pretty good so far, having a lot harder time adjusting to IntelliJ from Netbeans. My macros...
|
# ? Jun 11, 2018 22:30 |
|
Pedestrian Xing posted:Trip report: Mac pretty good so far, having a lot harder time adjusting to IntelliJ from Netbeans. My macros... Recommended by another goon a long time ago, but go get Key Promoter X plugin. It will tell you the hotkeys for things that you do often so you can pick them up quickly.
|
# ? Jun 12, 2018 18:08 |
|
Anyone familiar enough with file encoding to tell me why the hell Apache CSVParser is giving me unexpected output? I'm creating a reader, setting the expected file format to UTF-8, and applying that to the CSVParser: code:
code:
Column name ?Client_Product_ID does not match expected pattern and will be discarded! Edit: Apparently I hadn't Googled for the correct phrase up until now. Looks like its a bug that Apache made a utility for: BOMInputStream. PierreTheMime fucked around with this message at 18:10 on Jun 18, 2018 |
# ? Jun 18, 2018 17:15 |
|
Java Readers intentionally ignore the existence of a BOM in a string/file which is annoying. Commons-io has a BOMInputStream that will deal with it.
|
# ? Jun 18, 2018 17:46 |
|
I haven't seriously coded in Java for about 10 years, but I'm looking for a new job in the next few months so I'd like to get back into it in case any Java Dev jobs come up (that I'll still probably get rejected for due to the aforementioned lack of recent experience). I still have a couple of Java programming books I could use to refresh my memory, but they are for Java 5, and a cursory Google shows that Java is now on version 10. Has the language changed enough that it would be worth me looking into using some more up-to-date learning materials, or would I be alright re-learning from the books I have and then just learning about the more recent changes afterwards?
|
# ? Jun 18, 2018 21:16 |
|
Most of the changes from version to version are pretty minor, good java is still about the same as it was. That said, read up on lambdas and streams that we got in 8 or 9, super useful. (Although not really anything you couldn't do another way. But so much cleaner) also we have method references now, which goes with lambdas. Also maybe read up on some dependency injection framework.
|
# ? Jun 18, 2018 21:33 |
|
Yeah, your Java 5 book probably won't teach you too many bad habits. When you learn about streams and lambdas in Java 8, remember to consider readability and clarity as you construct monster, multi-step stream operations and you'll be fine.
|
# ? Jun 18, 2018 21:35 |
|
Read about Java Modules if you're curious why everyone seems to be staying on Java 8 instead of moving up.
|
# ? Jun 18, 2018 21:36 |
|
Java 9 modules feels like such a disappointment to me. The only reason I gave a poo poo is I thought it would provide a better solution to classpath hell by letting you mark certain dependencies as internal and not visible to consumers of your package. But no such luck.
|
# ? Jun 18, 2018 21:58 |
|
brap posted:Java 9 modules feels like such a disappointment to me. The only reason I gave a poo poo is I thought it would provide a better solution to classpath hell by letting you mark certain dependencies as internal and not visible to consumers of your package. But no such luck. Yep, that was going to be sweet instead of dumb.
|
# ? Jun 18, 2018 22:42 |
|
Most, Companies are still using Java 6 or 7 its rare to find one on Java 8 even,
|
# ? Jun 19, 2018 10:26 |
|
And at the same time, almost every job offer description I've seen over here requires knowledge of Java 8. (And AngularJS, but that's a different matter)
|
# ? Jun 19, 2018 11:32 |
|
TheresaJayne posted:Most, Companies are still using Java 6 or 7 its rare to find one on Java 8 even, What makes you say this? Data from Jet Brains's 2018 survey, Rebel Labs' 2017 report, and Plumbr's 2017 data all indicate that Java 8+ is in high use. This also matches with my experience at the local JUG whenever a speaker asks what version of Java we are using. Obviously, these all can be subject to self-selection bias, but I'd be interested if there is contradicting data.
|
# ? Jun 19, 2018 15:22 |
|
|
# ? May 9, 2024 01:33 |
|
I can't switch some of the web applications I've inherited to Java 8 because they're on Grails 2 and need to be upgraded to Grails 3 before they can handle Java 8. (I'm planning to upgrade them to "not Grails or Groovy anything," instead.)
|
# ? Jun 19, 2018 15:27 |