272 reputation
14
bio website
location
age
visits member for 2 years, 6 months
seen 2 days ago

Dec
13
comment Why use arg type `class Object` instead of `Comparable[]`?
"By the way, let's forget about generics for a moment: after all, early versions of Java, for which sort was implemented, did not provide generics." But the question doesn't have anything to do with generics -- both Object[] and Comparable[] are non-generic. So the "early versions of Java" could use Comparable[].
Dec
13
comment Why use arg type `class Object` instead of `Comparable[]`?
"Both checks can be done at runtime" If by "checked at runtime" you mean, try it and see if it throws an exception, then yes. Otherwise, #2 is not guaranteed to be checkable at runtime.
Dec
13
comment Why use arg type `class Object` instead of `Comparable[]`?
"one can be safe from runtime exceptions because every passed object has to implement interface Comparable" That would still not be safe from runtime exceptions. In order to sort, you need to make sure that the type is comparable to itself. You need a bound like <T extends Comparable<? super >>. Otherwise, it is still not safe. You will still get a warning.
Dec
10
comment Why is the hashCode method usage of HashSet not specified in the API?
@RossPatterson: Right, because sets and maps are analogous and can be implemented in terms of one another.
Dec
9
comment Why is the hashCode method usage of HashSet not specified in the API?
@RossPatterson: Well, it has to use .hashCode(), because the point of using HashSet is that it has average-case constant complexity for lookup, insertion, and deletion. And that is only possible if it uses .hashCode() for a hash table.
Dec
9
revised Why is the hashCode method usage of HashSet not specified in the API?
added 74 characters in body
Dec
9
answered Why is the hashCode method usage of HashSet not specified in the API?
Dec
5
answered Where is it specified that Java is call by value?
Dec
3
comment Performance of Class methods vs singleton instance methods
A class is an object and there is no difference in the process of sending a message to an object between if the receiver is a class or not. Every method is an "instance method" of some instance. Every method call goes through objc_msgSend (or related functions), and does not call any of the functions you listed above. However, there is a difference before the call in that a singleton object needs to be gotten somehow whereas a class object is known and hard-coded at compile-time.
Dec
2
comment Performance of Class methods vs singleton instance methods
@amon: However, to call instance methods on the singleton, he would presumably have to call something to "get" the singleton object, which is another call; whereas for calling a class method, the class object is provided directly.
Dec
1
comment What argument passing mechanism does python use, and where is this officially documented?
@delnan: In any language, "value" is an overly broad term. In C, when the parameter is a pointer type, is the "value" the address, or the thing pointed to? Same in Java. But "pass-by-value" and "pass-by-reference" should not depend on vague notions of terms like "value" -- Here is a definition only on semantics: when you assign to a parameter inside the function, and it has the same effect as assigning to the passed variable in the calling scope, that is pass-by-reference; when it has no effect on the calling scope, that is pass-by-value. This is consistent with how it is used in C++ and Java.
Dec
1
comment What argument passing mechanism does python use, and where is this officially documented?
@delnan: The only definition of pass-by-value/pass-by-reference that I have seen that is consistent across languages, and only relies on semantics and not vague terms, is the one where C/Java/Python/Ruby are pass-by-value only. No other definition I've seen commonly is used in a semantically consistent way.
Dec
1
comment What argument passing mechanism does python use, and where is this officially documented?
@delnan: I didn't say everything in Java is in Python. Types are not relevant, because Java is pass-by-value regardless of type. The semantics don't care about type. The same is true in Python. It's not "the Java terminology". It's the same terminology that is used in C, C++, and other languages (including Python, Ruby, etc.) by folks who have thought about it. The OP mentioned Java is pass-by-value, so it was a good place to compare to. The reasoning is independent of language.
Dec
1
answered What argument passing mechanism does python use, and where is this officially documented?
Nov
20
comment I want to understand clearly why can't we instantiate an object of an abstract class
"One or more parts of its public interface are not implemented." In Java, an abstract class doesn't have to have any abstract methods.
Nov
10
answered Coding style issue: Should we have functions which take a parameter, modify it, and then RETURN that parameter?
Oct
6
comment Calling static method from instance of class
[[instance class] staticMethod] does not resolve the method based on the static type of instance, but based on the dynamic class of the object pointed to by instance, so it is not like calling a static method on an instance in Java
Aug
9
comment British royal succession algorithm
I don't think citizenship matters. However, spouse's religion does.
Jul
28
comment Are closures sufficient to characterize functional programming?
@jozefg: same thing about Referential transparency. CL, SML, OCaml, Scheme, etc. are not referentially transparent. Only Haskell is referentially transparent.
May
25
awarded  Yearling