|
casual poster posted:I've never used a debugger before (it never came up during my lessons, I think netbeans comes with one though, I'll have to play around with it tomorrow. A lot of new programmers put off debuggers or don't know they exist or aren't taught about them for a long time, which is a huge mistake. They're a very easy and intuitive way to look into how your code is operating. Definitely learn debugging. Not complicated at all
|
# ? Feb 7, 2016 16:13 |
|
|
# ? Jun 1, 2024 19:58 |
|
Here's a post I wrote on how to use the debugger in Netbeans, with screenshots: http://forums.somethingawful.com/showthread.php?threadid=2780384&pagenumber=192&perpage=40#post441859581 e: and if you want to get really crazy, you can do what's called remote debugging, and not even have to be on the same computer as the program while you debug: http://forums.somethingawful.com/showthread.php?threadid=2780384&pagenumber=203&perpage=40#post449656064 Probably not useful to a beginner, but you can see the lengths to which programmers will go t omake their debugger available. It's really useful. carry on then fucked around with this message at 16:24 on Feb 7, 2016 |
# ? Feb 7, 2016 16:21 |
|
Zaphod42 posted:They're a very easy and intuitive way to look into how your code is operating. Definitely learn debugging. Not complicated at all Being able to pause your program exactly where you want and check out the current state is definitely a lot easier than playing a guessing game with logging statements all over your code, which most beginners end up doing anyway
|
# ? Feb 7, 2016 16:47 |
|
Holy crap, debugging is awesome! I had to look hard to find a good resource but this one helped me the best: http://www.itk.ilstu.edu/faculty/bllim/itk168/Labs/NetBeans_DebuggingW4/NetBeans_DebuggingW4_New.htm Btw "Carry on then" I didn't read your post until just now. THanks a lot for that. I wished I had checked into this thread this morning!
|
# ? Feb 8, 2016 00:32 |
|
Yeah debugging is loving huge. I'm almost surprised people don't teach that FIRST, before anything else, because it really is that useful. My only guess as to why they don't is maybe out of fear that you'd end up using the debugger as a crutch, testing out code brute-force style without learning what it does or how to anticipate or interpret what the compiler will do with a given bit of code. Which is important, but especially when you're new learning all the gotchas of the language can take time and watching them happen in the debugger is probably a more intuitive way to learn anyways. The alternative is a bunch of new programmers who just fill their code with System.out.println("Value of X: " + x); Every other line. Like what's the point in that when you can just use a debugger?
|
# ? Feb 8, 2016 17:38 |
|
If I want to put an application up as a .jar, what's the most user-friendly way to have it set up? In Eclipse, the options are Extract required libraries into JAR, Package required libraries into JAR, and Copy required libraries into sub folder next to JAR. From what I googled, I'm thinking Extract would keep it simplest?
|
# ? Feb 8, 2016 19:20 |
|
Zaphod42 posted:Yeah debugging is loving huge. I'm almost surprised people don't teach that FIRST, before anything else, because it really is that useful. Much like teaching source control, it's likely a case of instructors viewing it as outside the scope of their particular course/the degree (computer science isn't programming etc etc) and the instructors themselves not using/being familiar with it.
|
# ? Feb 8, 2016 19:24 |
|
22 Eargesplitten posted:If I want to put an application up as a .jar, what's the most user-friendly way to have it set up? In Eclipse, the options are Extract required libraries into JAR, Package required libraries into JAR, and Copy required libraries into sub folder next to JAR. From what I googled, I'm thinking Extract would keep it simplest? Package required libraries is AFAIK the best standard. That includes all the libraries into the JAR, but leaves them zipped in their own JARs. Extract would have all those packages unzipped as loose class files in folders which is just messier IMO. They should both work? Sub-folder next to JAR is the messiest by far as it means you have more files to distribute and they have to be in the right location. carry on then posted:Much like teaching source control, it's likely a case of instructors viewing it as outside the scope of their particular course/the degree (computer science isn't programming etc etc) and the instructors themselves not using/being familiar with it. Yeah you're right about that. Not teaching source control for years in academia is ridiculous but happens left and right. And then suddenly you have a course on project management and you have to use source control and everybody resists change.
|
# ? Feb 8, 2016 19:26 |
|
Can anyone recommend a book about the best practices of unit testing? I think that's one point where I definitely need to improve, particularly regarding setting up parameters and such. Java, and especially JUnit, are preferred.
|
# ? Feb 8, 2016 20:01 |
|
Yeah, come to think of it my university courses never taught the debugger. My CC classes were much more practical, and the teacher showed us how to use the debugger in both Eclipse and Visual Studio. Thanks, I'll package the files with the .jar. When I was in school we either submitted all of the files in a .zip or put together a .jar from the Linux terminal. E: packaged it up in its own folder since I've got a separate repository for the application. It only created the .jar, it didn't send any other files there. When I try to open it, nothing happens. Did I need to bring some other files over? I created it as a "Runnable Jar" if that makes a difference. E2: Turns out I needed to include the .txt files that the application reads information in from. 22 Eargesplitten fucked around with this message at 20:57 on Feb 8, 2016 |
# ? Feb 8, 2016 20:23 |
|
Zaphod42 posted:Yeah debugging is loving huge. I'm almost surprised people don't teach that FIRST, before anything else, because it really is that useful. I still end up writing plenty of the equivalent of printlines 10 years into my career. They are highly useful in helping to tract down issues which are not easily reproducible. Debuggers are great but the aren't always the most appropriate tool. HFX fucked around with this message at 21:51 on Feb 8, 2016 |
# ? Feb 8, 2016 21:48 |
|
HFX posted:I still end up writing plenty of the equivalent of printlines 10 years into my career. They are highly useful in helping to tract down issues which are not easily reproducible. Debuggers are great but the aren't always the most appropriate tool. Oh sure, same here. But its pretty obvious when somebody is using println()s as a crutch for not knowing what debugging is.
|
# ? Feb 8, 2016 21:54 |
|
Anyone got any reckons about using Optionals versus @Nullable/@NonNull annotations for wrangling them nulls? I've been using annotations and they're neat, nice and simple and the linter lets you know when you need to handle a potential null value. Are Optionals preferred since they don't rely on linting? Any other good reasons to use them?
|
# ? Feb 11, 2016 20:14 |
|
baka kaba posted:Anyone got any reckons about using Optionals versus @Nullable/@NonNull annotations for wrangling them nulls? I've been using annotations and they're neat, nice and simple and the linter lets you know when you need to handle a potential null value. Are Optionals preferred since they don't rely on linting? Any other good reasons to use them? They require Java 8 where as @Nullable / @NonNull can work back a few versions. I suppose both can be made to work reasonably.
|
# ? Feb 11, 2016 20:23 |
|
Well Guava has them (I'm not on the magic of Java 8) which I'm playing around with, and that's why I'm wondering if I should start using them
|
# ? Feb 11, 2016 21:01 |
|
Pulling in Guava as a dependency just for Optionals (or even any of their other nice stuff) is usually the limiting factor moreso than anything else, especially for those of us on Android where dex limits are a huge pain in the rear end even with multidex support being much improved.
|
# ? Feb 11, 2016 21:21 |
|
Well I mean just assuming they're there, since a lot of people add Guava as a dependency in general. Just looking for a general comparison here!
|
# ? Feb 11, 2016 21:41 |
|
We aggressively use Optionals, and we're very happy with it. It drastically cuts down on NPE's, and clarifies intent in interfaces. Also Java 8 is beautiful and nothing hurts. Except type erasure. gently caress that guy.
|
# ? Feb 12, 2016 05:53 |
|
Gravity Pike posted:We aggressively use Optionals, and we're very happy with it. It drastically cuts down on NPE's, and clarifies intent in interfaces. He's going to be around forever due to removing him would break a lot of old code and make some code next to impossible to do.
|
# ? Feb 12, 2016 07:32 |
|
Ok, so suddenly my project won't compile at all. Looking through my github stuff it doesn't seem like I have changed anything that could have caused this.code:
But now suddenly code:
From what I can see every one of these have a proper package header and stuff, so this is just plain weird. Any idea what it could be? Edit: apparently moving them to a sub-directory and back again in IDEA fixed it. Weird. Sistergodiva fucked around with this message at 12:29 on Feb 12, 2016 |
# ? Feb 12, 2016 12:09 |
|
Gravity Pike posted:We aggressively use Optionals, and we're very happy with it. It drastically cuts down on NPE's, and clarifies intent in interfaces. One of these days I'll get my head 'round lambda operators.
|
# ? Feb 12, 2016 21:13 |
|
Gravity Pike posted:We aggressively use Optionals, and we're very happy with it. It drastically cuts down on NPE's, and clarifies intent in interfaces. Speaking of type erasure, you wouldn't be able to do this with Optional: code:
code:
|
# ? Feb 12, 2016 21:32 |
|
Carbon dioxide posted:One of these days I'll get my head 'round lambda operators. Lambdas are pretty cool, I learned them many years back for C# and I was glad they were added to Java. They're pretty much just mixing in some declarative programming / functional programming in the middle of java's otherwise imperative programming style. Instead of writing code:
code:
The '->' arrow character is translated as "such that". (Person P such that p.getGender() == Person.Sex.MALE) Its like combining a for-each with an if() condition. You can also use them as a sort of function pointer, where you can pass a lambda operator as a parameter, which you can't otherwise do in Java. code:
Zaphod42 fucked around with this message at 21:43 on Feb 12, 2016 |
# ? Feb 12, 2016 21:37 |
|
They really clean up ActionListeners too.Java code:
Java code:
|
# ? Feb 12, 2016 22:03 |
|
CPColin posted:Speaking of type erasure, you wouldn't be able to do this with Optional: code:
|
# ? Feb 12, 2016 23:30 |
|
And what if setWhatever() needs to do something different when you pass it a null value?
|
# ? Feb 12, 2016 23:40 |
|
CPColin posted:And what if setWhatever() needs to do something different when you pass it a null value? If it's a setter on a POJO, why not let the constructor initialize it to a default value instead of relying on somebody remembering to call setWhatever(null);? That sounds absurdly contrived.
|
# ? Feb 13, 2016 00:04 |
|
Assume it's not a setter on a POJO, despite the name I arbitrarily gave it. Like, maybe these processValue() methods have to do something special, like display an error, when you pass in an empty Optional:code:
code:
code:
|
# ? Feb 13, 2016 00:19 |
|
CPColin posted:Assume it's not a setter on a POJO, despite the name I arbitrarily gave it. Like, maybe these processValue() methods have to do something special, like display an error, when you pass in an empty Optional: Yes, and I still say you shouldn't be doing that in the first place. That said, if you're stuck using legacy code with bizarre null semantics: code:
The Laplace Demon fucked around with this message at 01:42 on Feb 13, 2016 |
# ? Feb 13, 2016 01:40 |
|
Guava's optionals have a nice orNull() method.
|
# ? Feb 13, 2016 03:20 |
|
Java 8's have an .orElse(T val), so when our Optionals finally end up at the database layer, we have a lot of someValue.orElse(null) floating around our DAO code. Where lamdas really shine, in my opinion, is in the new CompletableFuture stuff. Lamdas make it especially convenient to chain things together. We've built up a generic "Retrier" class that lets us try things that might fail or timeout, essentially turning blocking code into asynchronous code: Java code:
|
# ? Feb 13, 2016 05:47 |
|
I need to make a method with a String parameter that compares that String to the (String)name parameter of all objects within an ArrayList. If the names match, I then have to set the parameters of an existing (currently null) variable equal to the object with the matching name in the ArrayList. I have a getName() method for the objects in the ArrayList, but no setter as the name variable is final. I have a for loop written with an if statement inside of that, but it isn't panning out. Happy to provide any missing info. Thanks for any help.
|
# ? Feb 14, 2016 22:46 |
|
What do you mean "isn't panning out"? Be specific: what are you expecting to happen, what is happening (an exception? wrong/no output? something else?) What code have you written so far?
|
# ? Feb 14, 2016 23:21 |
|
Also, do you get to use Java 8 features?
|
# ? Feb 14, 2016 23:33 |
|
carry on then posted:What do you mean "isn't panning out"? Be specific: what are you expecting to happen, what is happening (an exception? wrong/no output? something else?) What code have you written so far? The variable (selection) is initialized to null, and remaining that way because what I'm writing isn't actually changing it. I want the selection variable to essentially become a copy of an existing object within the ArrayList within makeSelection if the name parameter passed to makeSelection matches the name parameter of an existing item in the ArrayList. I have JUnit tests for a few cases; if the item is null, name is equal to NO_ITEM_SELECTION(passes), if the item name being input doesn't match an existing item name from the ArrayList, name is equal to NO_ITEM_SELECTION (passes), and if the name passed in matches that of an item already in the list, then selection.getName() is the same as the input. Using Eclipse Mars 4.5.0. Here's what I have: code:
SmellsLikeToast fucked around with this message at 02:04 on Feb 15, 2016 |
# ? Feb 15, 2016 01:59 |
|
SmellsLikeToast posted:
Ah, there we go.I'll just go ahead and say this right out because I know how unintuitive this is until you "get" it, which will come with time. == compares two variables for equality, and when the variables are Objects instead of primitives, the value of the variables is the reference to the object, not its contents. In essence, here you are checking if the name is the exact same object rather than if the two Objects are both Strings that contain the exact same characters in the exact same order, and of course that's coming up false. You'll want to use the equals() method on the String class to compare the two based on contents: https://docs.oracle.com/javase/7/docs/api/java/lang/String.html#equals(java.lang.Object) e to add: it was common back when I was tutoring that people would say "but it worked for me before." Occasionally == does appear to compare contents because people will do something like itemName = "my item" and then later on do something like (if itemName == "my item") and it'll seem to work. What actually happens is that for speed, the Java virtual machine notices hardcoded strings directly in your code, and creates one object with that string and shares it to all the places in your code where you used that String; this is called String interning. So in the first line you stored the single, interned String object representing "my item" and in the second statement, you compared against that very same object and it would come back as true despite not being a real comparison of the contents of the two strings. carry on then fucked around with this message at 02:44 on Feb 15, 2016 |
# ? Feb 15, 2016 02:37 |
|
Thanks. Somewhere in the back of my mind I knew that. Makes sense. I still can't manage to get the selection variable to take on the other object's parameters. I was thinking using the currentItem variable then setting selection equal to that would do it, but it doesn't seem to be. If it helps any, here's the JUnit test for the makeSelection method I can't get to pass.code:
|
# ? Feb 15, 2016 03:22 |
|
SmellsLikeToast posted:Thanks. Somewhere in the back of my mind I knew that. Makes sense. I still can't manage to get the selection variable to take on the other object's parameters. I was thinking using the currentItem variable then setting selection equal to that would do it, but it doesn't seem to be. If it helps any, here's the JUnit test for the makeSelection method I can't get to pass. There's another logic error in your loop. Let's say the item that matches is second from last, so at the end of that iteration, selection is equal to the Item you're looking for. Now do the last iteration with an item that isn't what you're looking for. Keep track of the value of currentItem and selection. Can you see why selection is guaranteed to be null unless the matching item is also the last item? You may want to try out the debugger for this. I'll paste in links to a post I made showing how to use the debugger a long time ago in the thread. carry on then posted:Here's a post I wrote on how to use the debugger in Netbeans, with screenshots: http://forums.somethingawful.com/showthread.php?threadid=2780384&pagenumber=192&perpage=40#post441859581
|
# ? Feb 15, 2016 03:31 |
|
carry on then posted:There's another logic error in your loop. Let's say the item that matches is second from last, so at the end of that iteration, selection is equal to the Item you're looking for. Now do the last iteration with an item that isn't what you're looking for. Keep track of the value of currentItem and selection. Can you see why selection is guaranteed to be null unless the matching item is also the last item? Yes, I see that. I'm guessing I need to do something with the index of the object that has the same name, but I don't know enough yet to know how to do that. Then again, could I just halt the loop at that point if those parameters match? In case it's not obvious, this is for an assignment. The problem I keep running into is the professors at my school take self-instruction to a whole new level. They basically just lecture on theory and logic then tell you what they want and that's about it. I usually don't have a problem with the logic end (as far as HOW it should work is concerned), I just don't have the knowledge of the API I need. I check stackoverflow and the Java API for every problem I run into but haven't been able to find what I need for this particular one. I appreciate your help.
|
# ? Feb 15, 2016 05:42 |
|
|
# ? Jun 1, 2024 19:58 |
|
SmellsLikeToast posted:Yes, I see that. I'm guessing I need to do something with the index of the object that has the same name, but I don't know enough yet to know how to do that. Then again, could I just halt the loop at that point if those parameters match? In case it's not obvious, this is for an assignment. The problem I keep running into is the professors at my school take self-instruction to a whole new level. They basically just lecture on theory and logic then tell you what they want and that's about it. I usually don't have a problem with the logic end (as far as HOW it should work is concerned), I just don't have the knowledge of the API I need. I check stackoverflow and the Java API for every problem I run into but haven't been able to find what I need for this particular one. I appreciate your help. You're closer than you think. If you want selection to be set only when the currentitem matches the one you're looking for, when should you be setting selection?
|
# ? Feb 15, 2016 16:00 |