Tuxide {l Wrote}:To the contrary; we all know a hash map is going to take up more memory than a list, yet lookup is faster. I don't think there's a correlation between memory usage and performance, unless your coding style is really bad.
StudioFortress {l Wrote}:It's not a fair way to judge; but for example jEdit tends to use more memory then pretty much every other text editor I've used, and NetBeans tends to use more then Visual Studio.
igouy {l Wrote}:StudioFortress {l Wrote}:It's not a fair way to judge; but for example jEdit tends to use more memory then pretty much every other text editor I've used, and NetBeans tends to use more then Visual Studio.
Until we see the memory usage you measured, and hear how you measured, we shouldn't give much weight to that claim :-)
igouy {l Wrote}:You "don't think there's a correlation between memory usage and performance" but you've just given an example of the time-space trade off negative correlation we all know?
charlie {l Wrote}:There's no denying that Java is memory heavy. If you need absolute efficiency, Java is probably not what you should be using.
StudioFortress {l Wrote}:I don't think Java is that high-level. With Haskell, Ruby and others you have plenty of examples where pages of Java code becomes a couple of lines. File IO is one good example. Even C++ has plenty of features which allow you to build more sophisticated and expressive abstractions then you can do in Java. Java is also often cited because of it's amazing verbosity.
As someone who has written a lot of Ruby, JavaScript and Java; I would say that with all things being equal, Java is the least productive. But things are not equal. Over the last 5 years I've learnt and used about 10 to 20 languages (including 2 I wrote myself), on and off. But over 70% of all of the code I have ever written, is in Java. As a result I am far more confident with Java, and so it's my most productive language, simply because I know it inside out.
What I am saying is that expressiveness is great, but confidence is really what gives you productivity.
Tuxide {l Wrote}:In Java, the norm is to make the compiler do as much of the work as possible so the work doesn't have to be done when you actually run your program, and that contributes to the verbosity of the language. This is why Java is a static-typed language and has generics (and why some people complain they're broken), because these are compiler features.
StudioFortress {l Wrote}:I personally think it's a bit lazy that static languages, like Java, force the developer to state the type in all places. For example Haskell is statically typed, but you don't specify types anywhere. The compiler works it all out for you using type inference. C# and C++ are also moving that way (a little), as they now allow you to infer types. Why should I have to write 'int' for 'int x = 5' ?
But in regards to the compiler, the standard Sun/Oracle compiler for Java actually does as little work as possible. Obviously it does static analysis, but essentially the compiler does a straight translation to bytecode, as quickly as possible. That is why it runs so fast, and the reason why is because you don't know what you are compiling for. It is the JVM which does all the work on optimizing.
Why should I have to write 'int' for 'int x = 5'
StudioFortress {l Wrote}:I don't think Java is that high-level.
import java.math.BigInteger;
import java.security.SecureRandom;
class Rsa {
private BigInteger n, d, e;
public Rsa(int bitlen) {
SecureRandom r = new SecureRandom();
BigInteger p = new BigInteger(bitlen / 2, 100, r);
BigInteger q = new BigInteger(bitlen / 2, 100, r);
n = p.multiply(q);
BigInteger m = (p.subtract(BigInteger.ONE)).multiply(q.subtract(BigInteger.ONE));
e = new BigInteger("3");
while(m.gcd(e).intValue() > 1) e = e.add(new BigInteger("2"));
d = e.modInverse(m);
}
public BigInteger encrypt(BigInteger message) {
return message.modPow(e, n);
}
public BigInteger decrypt(BigInteger message) {
return message.modPow(d, n);
}
}
Tuxide {l Wrote}:Inferring types might not be a bad idea, but still it is trivial because being able to do so in your code won't make your program run any faster or anything.
FreakNigh {l Wrote}:Why should I have to write 'int' for 'int x = 5'
The amount of memory that'll be used is different. The size of the number that can be stored in the variable will change. C / C++ has it's place in the embedded environment as well. C / C++ is for when your programming very close to the machine level so it's never going to make itself more like php or javascript or something.
FreakNigh {l Wrote}:C# and C++ should not be grouped together.
StudioFortress {l Wrote}:C# and C++ are also moving that way (a little), as they now allow you to infer types.
StudioFortress {l Wrote}:To clarify, I didn't mention Haskell because it's a functional language, but solely because of it's type inference, as it uses it quite heavily. I agree it won't make any difference to runtime performance, but it wouldn't degrade performance either. The reason why I'd like to see more type inference is because I would expect it would allow me to write type safe code, in less time, whilst being just as readable.
class Person { };
class Adult extends Person {
public static Adult newInstance() {
return new Adult();
}
public void payTaxes() { }
};
public static void main(String argv[]) {
p = new Person(); // Type-inferred, compiler says this is a Person, non-final
p = Adult.newInstance(); // Reassignment
p.payTaxes(); // Method is not a member of Person
}
m = new HashMap();
HashMap m = new HashMap();
Map m = new HashMap();
Map<String, List<Integer>> m = new HashMap<>();
Tuxide {l Wrote}:In comparison, JavaScript is designed for web use. Downloading and parsing a <script> resource is generally a blocking operation, and the bigger the resource file is, the longer this takes. This is why JavaScript is a dynamic-typed language and is more compact.
MyEmail {l Wrote}:Heck, who are we kidding? Real programmers code in scheme.
oberhamsi {l Wrote}:Tuxide {l Wrote}:In comparison, JavaScript is designed for web use. Downloading and parsing a <script> resource is generally a blocking operation, and the bigger the resource file is, the longer this takes. This is why JavaScript is a dynamic-typed language and is more compact.
script files are downloaded in parallel but executed in inclusion order. what this has to do with JS being dynamic is beyond me :)
public List<Foo> getFoos() {
}
public void example() {
auto foos = getFoos();
}
public List<Foo> getFoos() {
}
public void example() {
auto foos = getFoos();
foos = 5;
}
Tuxide {l Wrote}:Also, I know this is obvious but type inference could end up leading to tightly coupled code if you're not careful on where to use it. What I mean is this:
Map x = new HashMap()
Map x = new ArrayList()
ArrayList<Resizable2DArray<CachingHashSet<A>>> classPointsList = grid.getSubKeys( collisionClass );
auto classPointsList = grid.getSubKeys( collisionClass );
public auto bar( auto a, auto b ) {
return a + b ;
}
Tuxide {l Wrote}:oberhamsi {l Wrote}:Tuxide {l Wrote}:In comparison, JavaScript is designed for web use. Downloading and parsing a <script> resource is generally a blocking operation, and the bigger the resource file is, the longer this takes. This is why JavaScript is a dynamic-typed language and is more compact.
script files are downloaded in parallel but executed in inclusion order. what this has to do with JS being dynamic is beyond me :)
No it's not, least not the way I understood this. When a web browser processes a page and comes across a <script> element, it blocks processing of all elements coming after the script (including other <script> elements, <img> elements following the script, etc.) until the script is fetched and evaluated.
oberhamsi {l Wrote}:Used to be true, but see third column here (hover text reads ""This test determines if the browser downloads scripts in parallel with other scripts in the page."):
http://www.browserscope.org/?category=network
I was motivated enough to produce a picture to prove my point for chrome :)
When some browsers start downloading an external script, they wait until the script is done downloading, parsed, and executed before starting any other downloads. Although parsing and executing scripts in order is important for maintaining code dependencies, it's possible to safely download scripts in parallel with other resources in the page (including other scripts). This test determines if the browser downloads scripts in parallel with other scripts in the page.
StudioFortress {l Wrote}:Supporting type inference...
foo = Class.forName("java.lang.String").newInstance();
Map<Service, ServiceImpl> daos = new HashMap<Service, ServiceImpl>();
StudioFortress {l Wrote}:I don't fully agree. Yes when compiled, it would end up being the most explicit type possible. But writing 'auto' (or something else to denote type inference) would be more generic then writing 'Map'. For example lets say it changed from:
- {l Code}: {l Select All Code}
Map x = new HashMap()
... to ...
- {l Code}: {l Select All Code}
Map x = new ArrayList()
... your code is now broken. You would need to update the type of x from 'Map' to 'List' or 'ArrayList', in order to keep the code valid. If the type of x was automatic, using type inference, then the compiler would make this switch for you.
But that's nothing to do with the languages, it's comparing Java with its built in library, to raw C++ and trying to implement it yourself. Yes, one advantage is with Java the built in library - though you're also stuffed if you don't like what's there (I couldn't stand the UI toolkit, full of terrible bugs - maybe they've improved it in recent years, but that's not the point - the point was I couldn't just switch to another toolkit that worked).MyEmail {l Wrote}:StudioFortress {l Wrote}:I don't think Java is that high-level.
Consider this--in C++ it takes well over 2000 lines of code to write a basic RSA implementation. If you want it to be fast on multiple platforms and be secure enough to fit industry standards it takes much more than that. And this isn't the "easy" type of code I am talking about--it is hard, brutal (mathematical+logic * 100) kind of hard, the kind of hard developers spend years working on to get it right.
In Java you can do this in about 20 lines of code and 5 minutes of development time. Is Java a high-level language?
import java.math.BigInteger;
import java.security.SecureRandom;
class Rsa {
private BigInteger n, d, e;
public Rsa(int bitlen) {
SecureRandom r = new SecureRandom();
BigInteger p = new BigInteger(bitlen / 2, 100, r);
BigInteger q = new BigInteger(bitlen / 2, 100, r);
n = p.multiply(q);
BigInteger m = (p.subtract(BigInteger.ONE)).multiply(q.subtract(BigInteger.ONE));
e = new BigInteger("3");
while(m.gcd(e).intValue() > 1) e = e.add(new BigInteger("2"));
d = e.modInverse(m);
}
public BigInteger encrypt(BigInteger message) {
return message.modPow(e, n);
}
public BigInteger decrypt(BigInteger message) {
return message.modPow(d, n);
}
}
Users browsing this forum: No registered users and 1 guest