pull down to refresh
3 sats \ 4 replies \ @nerd2ninja 5 Aug 2022 \ on: What do you think about Googles new programming language Carbon? bitcoin
It does? I freaking hate Java. More of a ruby guy myself. Import your ruby.h file into your C project (Yes C not C++) and compile it for C level performance. Now that is appealing, at least to me.
What do you hate about Java?
reply
I definitely have a "first love" bias. As in the first language I learned can do no wrong and everything else just looks terrible (though ruby and python are so similar that I can easily switch to that)
You know just compare these two examples:
Ruby (this ruby code is not good, but you can tell it was made for people who are new and just trying to learn)
https://medium.com/@PolinaHackTech/count-vowels-in-a-string-in-ruby-app-academy-prep-work-20700832d2f5
Java:
public class CountVowelConsonant {
public static void main(String[] args) {
//Counter variable to store the count of vowels and consonant
int vCount = 0, cCount = 0;
//Declare a string
String str = "This is a really simple sentence";
//Converting entire string to lower case to reduce the comparisons
str = str.toLowerCase();
for(int i = 0; i < str.length(); i++) {
//Checks whether a character is a vowel
if(str.charAt(i) == 'a' || str.charAt(i) == 'e' || str.charAt(i) == 'i' || str.charAt(i) == 'o' || str.charAt(i) == 'u') {
//Increments the vowel counter
vCount++;
}
//Checks whether a character is a consonant
else if(str.charAt(i) >= 'a' && str.charAt(i)<='z') {
//Increments the consonant counter
cCount++;
}
}
System.out.println("Number of vowels: " + vCount);
System.out.println("Number of consonants: " + cCount);
}
}
Ruby
def count_vowels(string)
vowels = 0
counter = 0
while counter < string.length do
if string[counter]=="a" || string[counter]=="e" || string[counter]=="i" || string[counter]=="o" || string[counter]=="u"
vowels += 1
end
counter += 1
end
return vowels
end
def count_consonants(string)
consonants = 0
counter = 0
while counter < string.length do
if string[counter]!="a" && string[counter]!="e" && string[counter]!="i" && string[counter]!="o" && string[counter]!="u" && string[counter]!=" "
puts consonants += 1
end
counter += 1
end
return consonants
end
vowels = count_vowels("La la Land i like a lot")
consonants = count_consonants("La la Land i like a lot")
puts "#{vowels + consonants}"
But you know, maybe the more honest answer is that I don't know java and I do know ruby.
reply
No no, I get that. Programming Java is always a whole thing instead of just a small script. That makes it ugly. I get that.
reply
This example says nothing about the language but the programmers. The java code is not as elegantly written as the ruby code.
Indeed, putting everything in the main method instead of creating two separate ones is lazy and amateurish, and would not pass a serious code review.
reply