Today IntelliJ deflated my ego big time!
-
Working with my current favorite JavaFx using the IntelliJ IDE, I faced a problem earlier today. I had a two-dimensional array of objects to sort. Think for the array as something like: Object[][] myArray = new Object[88][155] Index 1 of each sub array held a string as an object. In other words myArray[][1] was a string object. The problem: To sort the array in alphabetical order for this string. I looked at the problem and thought: "No way is there a simple solution for this! I'm going to have to write a sorting class for the job. It took me a couple of hours but I got it working in less than 30 lines of code. And it worked well. Just as I was getting ready to pat myself on the shoulder, I developed a nagging thought (don't you just hate those spoiler nagging thoughts?) that I may have overlooked a more simple solution. So I did an online search and came across a solution to do the sort in some 6 or 7 lines. Skeptically I tried adapting the code to my situation. As I was about to try it out, up pops IntelliJ, suggesting it would be simpler to use a Lambda expression. It even offered to do the conversion for me. So I thought: "What the heck, let's give it a try. Sure enough IntelliJ's Lambda worked. About three lines of code! But IntelliJ was not done humiliating me. Up it pops with a suggestion that it can convert the Lambda to a "super lambda" or something of the sort. What could I do? I had to tell it to proceed and voila: The whole sorting action on a 2 dimensional object array done in a single line of code! Here it is: Arrays.sort(myArray, Comparator.comparing(o -> String.valueOf(o[1]).toLowerCase())); Tonight I will have nightmares of vicious IDEs chasing after me to correct all my many mistakes! :~
Get me coffee and no one gets hurt!
-
Working with my current favorite JavaFx using the IntelliJ IDE, I faced a problem earlier today. I had a two-dimensional array of objects to sort. Think for the array as something like: Object[][] myArray = new Object[88][155] Index 1 of each sub array held a string as an object. In other words myArray[][1] was a string object. The problem: To sort the array in alphabetical order for this string. I looked at the problem and thought: "No way is there a simple solution for this! I'm going to have to write a sorting class for the job. It took me a couple of hours but I got it working in less than 30 lines of code. And it worked well. Just as I was getting ready to pat myself on the shoulder, I developed a nagging thought (don't you just hate those spoiler nagging thoughts?) that I may have overlooked a more simple solution. So I did an online search and came across a solution to do the sort in some 6 or 7 lines. Skeptically I tried adapting the code to my situation. As I was about to try it out, up pops IntelliJ, suggesting it would be simpler to use a Lambda expression. It even offered to do the conversion for me. So I thought: "What the heck, let's give it a try. Sure enough IntelliJ's Lambda worked. About three lines of code! But IntelliJ was not done humiliating me. Up it pops with a suggestion that it can convert the Lambda to a "super lambda" or something of the sort. What could I do? I had to tell it to proceed and voila: The whole sorting action on a 2 dimensional object array done in a single line of code! Here it is: Arrays.sort(myArray, Comparator.comparing(o -> String.valueOf(o[1]).toLowerCase())); Tonight I will have nightmares of vicious IDEs chasing after me to correct all my many mistakes! :~
Get me coffee and no one gets hurt!
That's pretty impressive. I hadn't heard of Intellij, so I had to look it up. It doesn't support C++, so that's why. And I hope it never does, because I can imagine what it would do to my ego too!
Robust Services Core | Software Techniques for Lemmings | Articles
The fox knows many things, but the hedgehog knows one big thing. -
That's pretty impressive. I hadn't heard of Intellij, so I had to look it up. It doesn't support C++, so that's why. And I hope it never does, because I can imagine what it would do to my ego too!
Robust Services Core | Software Techniques for Lemmings | Articles
The fox knows many things, but the hedgehog knows one big thing.:laughs: And here I was, a day or 3 ago, a little surprised my new phone used autocement to alter "b4" into "by". The first time I tried out Augmented Reality on of all things, an Aldi catalog front-cover, my brain nearly melted. Ohhhhhhhhw - so that's why Pokemon Go has been so successful. :Checks last phone: - 7 years old.... :laugh:
-
Working with my current favorite JavaFx using the IntelliJ IDE, I faced a problem earlier today. I had a two-dimensional array of objects to sort. Think for the array as something like: Object[][] myArray = new Object[88][155] Index 1 of each sub array held a string as an object. In other words myArray[][1] was a string object. The problem: To sort the array in alphabetical order for this string. I looked at the problem and thought: "No way is there a simple solution for this! I'm going to have to write a sorting class for the job. It took me a couple of hours but I got it working in less than 30 lines of code. And it worked well. Just as I was getting ready to pat myself on the shoulder, I developed a nagging thought (don't you just hate those spoiler nagging thoughts?) that I may have overlooked a more simple solution. So I did an online search and came across a solution to do the sort in some 6 or 7 lines. Skeptically I tried adapting the code to my situation. As I was about to try it out, up pops IntelliJ, suggesting it would be simpler to use a Lambda expression. It even offered to do the conversion for me. So I thought: "What the heck, let's give it a try. Sure enough IntelliJ's Lambda worked. About three lines of code! But IntelliJ was not done humiliating me. Up it pops with a suggestion that it can convert the Lambda to a "super lambda" or something of the sort. What could I do? I had to tell it to proceed and voila: The whole sorting action on a 2 dimensional object array done in a single line of code! Here it is: Arrays.sort(myArray, Comparator.comparing(o -> String.valueOf(o[1]).toLowerCase())); Tonight I will have nightmares of vicious IDEs chasing after me to correct all my many mistakes! :~
Get me coffee and no one gets hurt!
Cp-Coder wrote:
String.valueOf(o[1]).toLowerCase()
Nit-picking: Depending on your data, you should normalize strings to upper-case, to avoid the "Turkish i" problem. :) The Turkish İ Problem and Why You Should Care | You’ve Been Haacked[^] (The article is about .NET, but the problem will affect other languages as well.) In .NET, it's better to pass in a case-insensitive
StringComparisonOptions
orStringComparer
rather than changing the case of the string, so that you don't have to create a new string for every comparison. I don't know whether Java has anything similar, or suffers from the same problem.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
Cp-Coder wrote:
String.valueOf(o[1]).toLowerCase()
Nit-picking: Depending on your data, you should normalize strings to upper-case, to avoid the "Turkish i" problem. :) The Turkish İ Problem and Why You Should Care | You’ve Been Haacked[^] (The article is about .NET, but the problem will affect other languages as well.) In .NET, it's better to pass in a case-insensitive
StringComparisonOptions
orStringComparer
rather than changing the case of the string, so that you don't have to create a new string for every comparison. I don't know whether Java has anything similar, or suffers from the same problem.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
Cp-Coder wrote:
String.valueOf(o[1]).toLowerCase()
Nit-picking: Depending on your data, you should normalize strings to upper-case, to avoid the "Turkish i" problem. :) The Turkish İ Problem and Why You Should Care | You’ve Been Haacked[^] (The article is about .NET, but the problem will affect other languages as well.) In .NET, it's better to pass in a case-insensitive
StringComparisonOptions
orStringComparer
rather than changing the case of the string, so that you don't have to create a new string for every comparison. I don't know whether Java has anything similar, or suffers from the same problem.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
Richard Deeming wrote:
In .NET, it's better to pass in a case-insensitive
StringComparisonOptions
orStringComparer
rather than changing the case of the string:thumbsup:
-
Cp-Coder wrote:
String.valueOf(o[1]).toLowerCase()
Nit-picking: Depending on your data, you should normalize strings to upper-case, to avoid the "Turkish i" problem. :) The Turkish İ Problem and Why You Should Care | You’ve Been Haacked[^] (The article is about .NET, but the problem will affect other languages as well.) In .NET, it's better to pass in a case-insensitive
StringComparisonOptions
orStringComparer
rather than changing the case of the string, so that you don't have to create a new string for every comparison. I don't know whether Java has anything similar, or suffers from the same problem.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
:thumbsup: I have a case-insensitive string comparison function in C++. But it normalizes to lower case, so I'll have to read that article. I know that Turkish has an undotted i, but it'll be interesting to learn why that creates a problem.
Robust Services Core | Software Techniques for Lemmings | Articles
The fox knows many things, but the hedgehog knows one big thing. -
That's pretty impressive. I hadn't heard of Intellij, so I had to look it up. It doesn't support C++, so that's why. And I hope it never does, because I can imagine what it would do to my ego too!
Robust Services Core | Software Techniques for Lemmings | Articles
The fox knows many things, but the hedgehog knows one big thing.They have another IDE called CLion that's basically just a customised/simplified IntelliJ - It's much better than Visual Studio, but I don't really know how it stacks up compared to other C++ Editors.
-
They have another IDE called CLion that's basically just a customised/simplified IntelliJ - It's much better than Visual Studio, but I don't really know how it stacks up compared to other C++ Editors.
I know quite a few people who rate it - never tried it myself, mind!
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
-
Working with my current favorite JavaFx using the IntelliJ IDE, I faced a problem earlier today. I had a two-dimensional array of objects to sort. Think for the array as something like: Object[][] myArray = new Object[88][155] Index 1 of each sub array held a string as an object. In other words myArray[][1] was a string object. The problem: To sort the array in alphabetical order for this string. I looked at the problem and thought: "No way is there a simple solution for this! I'm going to have to write a sorting class for the job. It took me a couple of hours but I got it working in less than 30 lines of code. And it worked well. Just as I was getting ready to pat myself on the shoulder, I developed a nagging thought (don't you just hate those spoiler nagging thoughts?) that I may have overlooked a more simple solution. So I did an online search and came across a solution to do the sort in some 6 or 7 lines. Skeptically I tried adapting the code to my situation. As I was about to try it out, up pops IntelliJ, suggesting it would be simpler to use a Lambda expression. It even offered to do the conversion for me. So I thought: "What the heck, let's give it a try. Sure enough IntelliJ's Lambda worked. About three lines of code! But IntelliJ was not done humiliating me. Up it pops with a suggestion that it can convert the Lambda to a "super lambda" or something of the sort. What could I do? I had to tell it to proceed and voila: The whole sorting action on a 2 dimensional object array done in a single line of code! Here it is: Arrays.sort(myArray, Comparator.comparing(o -> String.valueOf(o[1]).toLowerCase())); Tonight I will have nightmares of vicious IDEs chasing after me to correct all my many mistakes! :~
Get me coffee and no one gets hurt!
M.D.V. ;) If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you Rating helpful answers is nice, but saying thanks can be even nicer.