|
Volguus posted:A bit late to the question, but servlets are not archaic at all. They are used today by ... everything really. Spring itself (or any other framework) still has a dispatcher servlet that listens to the request, looks at the parameters and headers and HTTP verb and then decides what class to call, what method with what params. JSPs themselves become servlets, then compiled into bytecode. While it is true that most developers nowadays do not write servlets anymore and do not have to deal with its awful "servletOutputStream.println" peppered everywhere (or templated, but same poo poo really), it is still extremely important for a developer to know what goes on underneath all that magic. Do your homework, learn how to write them and don't forget all of that when you move to greener pastures. we're in agreement, I said that the web API (servlets/filters/etc) are some of the few parts of Java EE that remain directly relevant (vs most of the rest of EE where anyone who is not deep in the poop writing their own application server will never need to know), but that in most cases (barring things like file transfers/etc) you won't be touching them directly. Paul MaudDib fucked around with this message at 00:18 on Jul 29, 2020 |
# ? Jul 29, 2020 00:15 |
|
|
# ? Jun 6, 2024 15:43 |
|
Paul MaudDib posted:deep in the poop writing their own application server Yep
|
# ? Jul 29, 2020 00:28 |
|
If you follow the instructions in eclipse for creating a helloworld, you get code:
|
# ? Jul 30, 2020 12:16 |
|
Man, that post made me realize that despite 6 years of professional Java experience I just have no idea how JPMS works.
|
# ? Jul 30, 2020 16:26 |
|
uguu posted:If you follow the instructions in eclipse for creating a helloworld, you get People have very strong feelings about IDEs. I am willing to work with most anything but Eclipse.
|
# ? Jul 30, 2020 19:06 |
|
Hekk posted:People have very strong feelings about IDEs. I am willing to work with most anything but Eclipse. eclipse is my go-to example of why you don't let engineers design UIs. I think it's widely agreed that intelliJ is the way to go, especially if you are eligible for a student license or are willing to work around the limitations on the "free" edition
|
# ? Jul 30, 2020 19:13 |
|
carry on then posted:Man, that post made me realize that despite 6 years of professional Java experience I just have no idea how JPMS works. How do you avoid it then? I just used an older version of the jre, but this was for a one off.
|
# ? Jul 30, 2020 20:53 |
|
uguu posted:How do you avoid it then? Everything we write has to be source and target compatible with 8 if not 6. So I guess we never put our code in JPMS modules. Plus the main products already used OSGi and have for years/decades.
|
# ? Jul 30, 2020 22:42 |
|
I can't for the life of me figure out how to fit this stupid question into a google search. So I want to have a button on each item on my page that will take you to a page with all the item details. (They're cars) I know I want to use the vin number as the unique id's, I just don't know how to even start writing the servlet. edit: I know this is a fantastically stupid question but we kind of were just given a basic 1 day overview on servlets and cut loose on this. Guildenstern Mother fucked around with this message at 17:38 on Aug 6, 2020 |
# ? Aug 6, 2020 17:09 |
|
Do you have the HTML structure for your page figured out? What are you using for your view (JSP, thymeleaf, are you writing out HTML in your servlet)? In any case what you want is a servlet that has a URL mapping likepre:/car/{VIN}
|
# ? Aug 6, 2020 19:55 |
|
Guildenstern Mother posted:I can't for the life of me figure out how to fit this stupid question into a google search. So I want to have a button on each item on my page that will take you to a page with all the item details. (They're cars) I know I want to use the vin number as the unique id's, I just don't know how to even start writing the servlet. What Janitor Prime recommended will work, but if I remember correctly (it's been 20 years since I last wrote plain servlets) it's a bit of a pain to have dynamic paths like that. With spring & co it's a trivial matter but not with plain servlets. The easiest way is to accept query parameters. So you have your CarDetailsServlet which is mapped to /car path and is called like this: /car?vin=ABCD Then in it's doGet method, you simply call HttpServletRequest.getParameter("vin") and you get the VIN and you're off to the races.
|
# ? Aug 7, 2020 03:04 |
|
Over on my new workplace I had first discussions about which way to go to overhaul and ditch a bunch of old-rear end Foxpro applications. The IT department is a Java/Eclipse shop, so I have been loosely looking at things recently. I'm not too excited about SWT so far. Are there any other more modern (looking/themable) UI toolkits that can be used in the Eclipse environment? (--edit: The applications will run on Windows.) Personally, I'd rather be dealing with Electron (or something similar), but it's uncertain I can push this yet. More so, since they'd like to do REST APIs returning JSON (instead of crawling the DB400 with SQL queries), and considering the first two letters of the output format...
|
# ? Aug 15, 2020 15:30 |
|
Combat Pretzel posted:Over on my new workplace I had first discussions about which way to go to overhaul and ditch a bunch of old-rear end Foxpro applications. The IT department is a Java/Eclipse shop, so I have been loosely looking at things recently. I'm not too excited about SWT so far. Are there any other more modern (looking/themable) UI toolkits that can be used in the Eclipse environment? (--edit: The applications will run on Windows.) As far as UI toolkits, the most modern one I know of is JavaFX which should probably work in Eclipse-based apps but if you're writing an Eclipse plugin you're stuck. As far as handling JSON, just pull in a library like Jackson or Yasson and handle it that way. While I'm sure that you personally want to use JS, if the rest of the org has Java experience and existing Java code, there are a multitude of reasons to stick with Java.
|
# ? Aug 15, 2020 15:55 |
|
Perhaps TornadoFX could be interesting as well?
|
# ? Aug 15, 2020 16:04 |
|
carry on then posted:While I'm sure that you personally want to use JS, if the rest of the org has Java experience and existing Java code, there are a multitude of reasons to stick with Java. The Foxpro crap was introduced like 16 years ago, already late as it is in regards to technology of choice, and it was eventually dropped in the lap of a computer nerd in the office, that taught himself some basic programming and SQL to maintain them. Since Foxpro is obsolete as gently caress, it eventually needs replacement. More so with IT's plans of hiding database access behind REST APIs. I'd rather not be cornered into a solution I'd not like. My own opinion is that if I need to write a bunch of applications that do a lot of wild visualizations (management likes pictures), I'd need a capable environment for this. At least on first glance, SWT doesn't really look the part, and generating a bunch of HTML and SVG inside Electron seems a better option than dealing with a two digit amount of third party components. Not to mention, if I'm writing an app, I'd like it to look like the decade it was conceived in. Their current stuff looks like it came from the nineties. However if push comes to shove, I'd like to know my options. Also, my predecessor claims that the three Java programmers upstairs can't grasp Excel's VLOOKUP, which is pretty in itself, so I'd rather avoid associating with them to begin with by going my own way. Otherwise I'd have to do training sessions with them to get up to speed with their coding practises. Sagacity posted:Perhaps TornadoFX could be interesting as well?
|
# ? Aug 15, 2020 16:41 |
|
SWT can certainly do what you're asking. There is no reason not to. The only objection to SWT that one may have is how it looks and how easy/hard is it to apply a theme to it. Other than that, anything that you can do in Electron you can do in SWT, just with different technologies. But, if you're really set on HTML/JS, both SWT and JavaFX can display web pages, albeit not at the speed and capability of a full blown chromium browser, which is what Electron is. Building a full desktop HTML application in SWT or JavaFX would not be recommended. JavaFX on the other hand (let's ignore Swing as it is quite old and not sure if even maintained anymore), can be made to look in any way you wish. Check out this page for some examples. And yes, you can use JavaFX in any IDE you want, Eclipse included. But, if you're set on web technologies, why not build a web application directly? In the browser. Why go with a desktop app?
|
# ? Aug 15, 2020 16:55 |
|
Yea, if you are modernizing a bunch of internal apps I would suggest going with a web interface instead, if possible. You are going to be running a server to process everything into JSON already. Otherwise use JavaFX
|
# ? Aug 15, 2020 17:06 |
|
Volguus posted:But, if you're set on web technologies, why not build a web application directly? In the browser. Why go with a desktop app? --edit: Gonna take a while before actually starting anyway. I first have to go through tons of Foxpro code and document that bitch. Because there's none of that, either. --edit: Volguus posted:JavaFX on the other hand (let's ignore Swing as it is quite old and not sure if even maintained anymore), can be made to look in any way you wish. Check out this page for some examples. Combat Pretzel fucked around with this message at 17:57 on Aug 15, 2020 |
# ? Aug 15, 2020 17:38 |
|
Combat Pretzel posted:I don't know. If it's enforced to go Java, the idea out of the window anyway. Otherwise, I suppose to have a stable environment for the app to run in, to avoid weird issues after browser updates. Plus I think it's easier to tie native code components into Electron? If that's gonna be necessary. Yeah, if you have to go Java and desktop is your only option, then Electron is out the window as well. Browsers lately have been quite stable and relatively standards conforming though. Nothing is perfect and there are every now and then weird bugs popping up, but you won't avoid that with Java either. While I do not have experience with Electron native (writing a c++ application that embedded the V8 JS engine doesn't count), Java native is not bad. But, if you need to go native too much, I'd reconsider the entire Java choice as well. Maybe a native desktop application would be more appropriate.
|
# ? Aug 16, 2020 03:17 |
|
Volguus posted:(let's ignore Swing as it is quite old and not sure if even maintained anymore) It is. All the jetbrains ides are pure swing and they look modern enough to my eye
|
# ? Aug 18, 2020 10:40 |
|
It's maintained, but I'd say that Swing requires a ton of effort to make it look and work as well as Jetbrains does.
|
# ? Aug 18, 2020 13:41 |
|
Kotlin Spring question: If I've got an incredibly slow network call (6+ seconds) that can safely be cached for moderate periods of time (5 minutes), and using stale old cached values is acceptable, is there any clean way for me to get background threads to refresh the cache without any real requests paying that horrible penalty? Basically, what I want is for this to schedule cache renewal, and somehow keep serving the old cached value while waiting for the new one to populate. code:
If I do sync="true" in @Cacheable, then they'll at least use the first response rather than waiting on their own, but will still not use the previously cached value and be stuck waiting. I don't see an easy way to do this other than stepping pretty far outside of easy Spring norms and manually managing a volatile property and managing the in-memory caching myself. I guess what I would do there is have a @Scheduled method that makes the slow call, reads it into a new object, and then in a single atomic operation reassigns the volatile property on the class.
|
# ? Aug 21, 2020 02:32 |
|
I'm honestly surprised Spring doesn't already have an obvious way to do that; it seems like a pretty standard policy for managing cached data.
|
# ? Aug 21, 2020 02:42 |
|
@CachePut seems like the obvious solution.
|
# ? Aug 21, 2020 02:53 |
|
Jabor posted:@CachePut seems like the obvious solution. CachePut does exactly that and I have no idea how I had missed it, thank you!
|
# ? Aug 21, 2020 03:12 |
|
I'm new to IntelliJ. Around 1:21 in https://www.youtube.com/watch?v=hi85qx6006A&t=81s It looks like they replace expressions like dirty > 30 with the variable isDirty that was defined to be that in a single keystroke. I assumed this would be somewhere in the refactoring menu, but I couldn't quickly find online or in IntelliJ what they might have done. Any idea what keyword I should be searching for? Are they just pasting something? dirby fucked around with this message at 16:11 on Aug 24, 2020 |
# ? Aug 24, 2020 16:09 |
|
dirby posted:I'm new to IntelliJ. Around 1:21 in It looks like they are copying and pasting; the cursor goes off to the left and back every time they make a change.
|
# ? Aug 24, 2020 17:43 |
|
Yeah they're just demonstrating a different way of writing the code to make the when block more readable It's not 1 keypress but if you have cursor over the expression you can do Extract Variable (ctrl+alt+V) it'll pull it out to whichever scope you want and let you rename it, sometimes it even guesses a good name! Having the cursor over > instead of dirty will usually give you a more relevant first suggestion so you can just hit enter
|
# ? Aug 24, 2020 22:01 |
|
Its nice and sane, all the refactoring shortcuts follow the same pattern. V for variable, m for method, p for parameter, c for constant, probably some more I dont use often enough to remember.
|
# ? Aug 29, 2020 14:37 |
|
Does anyone else here really hate conditionals and try to work around them? I feel they are unclean code, but I end up always having to have a conditional somewhere which leads to an inevitable if-else block or ternary operator. I probably abuse ternary operators way too much since I feel it's more concise. For example, if I have a method that takes a bunch of arguments and every single thing in the method is the same except for an outgoing call that returns a specific object that needs to be used for the rest of the method, I'll slap a ternary operator and do something like this: // assuming there is an argument flag that indicates the desire for a Foo or a Bar, and this flag would be: boolean foo FooBar fb = foo ? Utils.getMeFoo() : Utils.getMeBar(); Possible alternatives is to just make some Utils.getMeFooOrBar but then I still push the conditional down the chain, by doing Utils.getMeFooOrBar(foo); and it'd still have the ternary in there. I hate it. I hate it so much and I don't know why.
|
# ? Aug 31, 2020 19:02 |
|
You can do pseudo pattern matching by passing types around and using instanceof, or you can possibly hand wave it away with some other structures, but it is as you say just pushing it down the chain. It calls for a boolean because you are in a boolean situation. Embrace it. I don't like it when it starts nesting multiple levels and with different booleans in each one, that's where functional programming's pattern matching starts paying off as it looks much tidier and can guarantee that you've covered all cases.
|
# ? Aug 31, 2020 19:37 |
I mean, I don't think you can reasonably be a programmer, hate conditionals, and expect to maintain your sanity. It's literally a fundamental instrument of programming - languages are basically just choices and arithmetic, and everything else is sugar. Conditionals can definitely be a huge source of unclean code, though - cognitive complexity is an important consideration, and every time you add a branch to your code you increase it. Given that you use ternary operators a lot, it sounds to me like you just don't like nested blocks, which is fair - over-nesting can lead to some gross, hard-to-maintain code. Ternary operators are great, when used responsibly. Your use case there is fine IMO (unless you're specifically making a FooBar object to hold a Foo or a Bar, neither of which have anything to do with each other, but that's a violation of SRP rather than an issue with ternaries), it's when you get into code:
At the end of the day, you have to remember that a primary purpose of your code is for communication with your team members, viz. What The gently caress This Bit Of Code Is Doing. Choose your conditional structures based on what other people will be able to understand, rather than trying to win code golf or pursuing code aesthetic purity
|
|
# ? Aug 31, 2020 19:41 |
|
ChickenWing posted:I mean, I don't think you can reasonably be a programmer, hate conditionals, and expect to maintain your sanity. It's literally a fundamental instrument of programming - languages are basically just choices and arithmetic, and everything else is sugar. Aye, I agree wholeheartedly, I feel there's a better way but I can't quite grasp it. Some sort of mediator impl or something... but honestly, who wants to put all that up when you can just do if-else instead? That ternary nesting is absolutely nasty though. I only use ternary operators when... 1) I need to assign a value to a object but I have to branch, and it's supremely annoying to repeatedly type: code:
2) I am making a method call but there's a quick value switch to null (but the original value is still used elsewhere in this hypothetical, otherwise fooObject could just be set to null beforehand) based on a flag and I didn't want to make a conditional just to call the same method two times but with slightly different code: code:
code:
|
# ? Aug 31, 2020 22:06 |
|
nakieon posted:Does anyone else here really hate conditionals and try to work around them? I feel they are unclean code, but I end up always having to have a conditional somewhere which leads to an inevitable if-else block or ternary operator. I probably abuse ternary operators way too much since I feel it's more concise. If a conditional gets too big or complex, I try to replace it with a lookup table. In the average case, lookup tables are faster and, to my eyes, cleaner. Personally, I hate the ternary operator. For whatever reason, it takes my brain longer to grok an assignment that utilizes it.
|
# ? Aug 31, 2020 23:14 |
|
nakieon posted:Does anyone else here really hate conditionals and try to work around them? I feel they are unclean code, but I end up always having to have a conditional somewhere which leads to an inevitable if-else block or ternary operator. I probably abuse ternary operators way too much since I feel it's more concise. You might find these interesting: https://medium.com/edge-coders/coding-tip-try-to-code-without-if-statements-d06799eed231 https://alisnic.github.io/posts/ifless/ There are some interesting ideas but I think pursuing this to extreme levels is a bit silly. Your code is there to clearly express your intentions to other programmers primarily. A ternary operator and an if statement end up as the same bytecode, as far as I know. It's just syntactic sugar for an if-else statement so you could argue that it's no cleaner. chippy fucked around with this message at 14:23 on Sep 1, 2020 |
# ? Sep 1, 2020 11:24 |
|
Ither posted:If a conditional gets too big or complex, I try to replace it with a lookup table. In the average case, lookup tables are faster and, to my eyes, cleaner. I generally go through the following thought process Is my conditional logic simple ? Use ternary operators : otherwise use if statements.
|
# ? Sep 1, 2020 19:21 |
Che Delilas posted:: otherwise
|
|
# ? Sep 1, 2020 19:31 |
|
I prefer how Kotlin and Scala just use if as the ternary. https://kotlinlang.org/docs/reference/control-flow.html https://alvinalexander.com/scala/scala-ternary-operator-syntax/
|
# ? Sep 3, 2020 15:40 |
|
Che Delilas posted:I generally go through the following thought process I... wow. That is a great post. I read this 3 days ago and something just felt off about it. Less than a minute ago I just realized you structured your last sentence in the ternary operator pattern: boolean ? expression1 : expression2 Amazing.
|
# ? Sep 5, 2020 05:26 |
|
|
# ? Jun 6, 2024 15:43 |
|
nakieon posted:I... wow. That is a great post. I read this 3 days ago and something just felt off about it.
|
# ? Sep 5, 2020 06:50 |