2,069 reputation
410
bio website
location Illinois
age 44
visits member for 2 years, 3 months
seen 2 days ago

Oct
8
comment Combinatorial explosion of interfaces: How many is too many?
...or property to read out element N of the array, but no methods which write the array or expose a direct reference. Code which has references to such an "immutable sequence" objects can act as though each reference is an independent immutable sequence. References to such objects may be freely shared among threads, and may be copied or destroyed without having to worry about maintaining a thread-synchronized global count of the number of references that exist. I'd call that a pretty big win for GC.
Oct
8
comment Combinatorial explosion of interfaces: How many is too many?
@Dennis: In C++, if a method needs to return something that represents an immutable sequence of up to one million integers, the from my understanding any method which is given that sequence and wants to hold onto it, it will be necessary to either make a new copy of the sequence, perform a synchronized thread-safe update of a reference-counter or other usage-tracking mechanism. In C# or Java, the method can simply return a reference to an object which has a constructor creates an array of suitable size, puts stuff into it, and stores a reference into a private field, and a method...
Oct
7
comment Is there an “ask for only what you need” interface principle?
PS--while the ability to apply multiple interface constraints to generic type parameters is cool, there is in general no way without using Reflection to pass a reference of type Object as a parameter of a multiply-constrained type unless all the instances that might be passed have a common supertype which satisfies all the constraints. In many cases, no such type will exist.
Oct
7
comment Is there an “ask for only what you need” interface principle?
Now imagine one wants the ability to wrap a collection with an object that can do everything the collection can do, but which logs every transaction. How many wrappers would one need? If all collections inherited from a common interface which included properties to identify their abilities, one wrapper would suffice. If all interfaces are distinct, however, one would need dozens.
Oct
7
comment Is there an “ask for only what you need” interface principle?
Arrays, for example, would support ECRW. An arraylist would support ECRWIDNA. A thread-safe list might support ECRWNA [though A would generally only be useful for pre-populating the list]. A read-only array wrapper might support ECR. A covariant list interface could support ECRD. A non-generic interface could provide type-safe support C or CD. If Swap was an option, some types could support CS but not D (e.g. arrays) while others would support CDS. Trying to define distinct interface types for each necessary combination of abilities would be a nightmare.
Oct
7
comment Is there an “ask for only what you need” interface principle?
If client code might need something that can be used as IFoo and IBar, defining a composite IFooBar may be a good idea, but if interfaces are finely split it's easy to end up requiring dozens of distinct interface types. Consider the following features collections might have: Enumerate, report Count, Read nth element, Write nth element, Insert before nth element, Delete nth element, New item (enlarge collection and return index of new space), and Add. Nine methods: ECRWIDNA. I could probably describe dozens of types which would naturally support many many different combinations.
Oct
7
comment Combinatorial explosion of interfaces: How many is too many?
@Dennis: Another thing to consider is that a typical modern GC will know nothing about most objects that are abandoned. The GC keeps a list of objects that are "special" in various ways, and after each GC cycle will need to inspect all such items that might have been abandoned, but if an object is abandoned and isn't on one of those lists, the memory it used to occupy will be wiped wholesale without any concern for what sorts of objects it might have formerly contained. This is very different from C++ where the memory manager which needs to individually release every object's memory.
Oct
7
comment Combinatorial explosion of interfaces: How many is too many?
@Dennis: In C++, the statement foo=bar; requires notifying the previous thing to which foo held a reference that it now has one fewer reference, and notifying the thing to which bar held a reference that it has one more. In C# or Java, the statement simply copies 32 or 64 bits from variable bar to variable foo. Most C# code that uses e.g. String doesn't care that a variable of type String holds a reference to an object. All it cares about is that given such a variable, it can either read out the contents as characters, or pass it to other code that expects a String.
Oct
7
answered Why should your code not use 100% CPU?
Oct
6
comment Why was Fortran never used to develop an Operating System?
The lack of pointer support is the fundamental problem. One of the main jobs of an OS is to subdivide memory based upon demands made at runtime, but FORTRAN has traditionally required that each program must specify its memory requirements before it can do anything else. A FORTRAN implementation could code to allow arbitrary sorts of low-level I/O by defining functions to e.g. "read I/O register N" or "store M to I/O register N" or even read/write arbitrary memory addresses, but it would have no facility to have "ordinary" statements interpret memory in ways determined at runtime.
Oct
6
comment How many are too many interfaces on a class?
...an ArrayList should not have to skip over 999,999 items to read the 1,000,000th. In languages which do not provide a "default interface implementation" facility one may end up with a lot of boilerplate code that makes it seem as though objects are implementing an excessive number of methods, but if there's no concept of "enumerable collection that may or may not support a fast way to get the Nth thing, but can be asked if it does", it will be very difficult to implement a "read only wrapper for an enumerable collection that may or may not have a fast way to get the Nth thing".
Oct
6
comment How many are too many interfaces on a class?
In cases where a base interface would be allow code to do many things with an object, but for most of those things at least some implementations would have a more efficient means than using the base interface, I would favor having such things included in the base interface even if the only thing most implementations to is chain to a static method. For example, just about any kind of enumerable collection could implement a method "get the Nth thing" by creating an enumerator, advancing it by N, and returning the next item, but...
Oct
6
comment Combinatorial explosion of interfaces: How many is too many?
@Dennis: Knowing the ownership of mutable objects is absolutely critical; IMHO Java would have been a much better language had Gosling et al. encouraged the use of Hungarian notation to distinguish between methods which return a live view of a mutable object, those which return a detached copy, and those which may do either at the implementer's convenience. Since such information is vital, but nothing in the type system encapsulates it, Hungarian notation would have made it available where it was needed. For immutable objects, however, such issues aren't important.
Oct
6
comment Combinatorial explosion of interfaces: How many is too many?
@Dennis: How would you define the ownership of a String which, after being created in .NET or Java, has references to it stored in a variety of fields, array slots, and collections, which are for the most part unaware of each others' existence? I agree that Java and .NET have failed to recognize the most fundamental purpose of immutability. Immutability doesn't describe something that an object can't do, but rather something it can: serve as a substitute for any other immutable object whose state has ever been directly or indirectly observed as or known to be be equivalent.
Oct
4
answered Why were Java collections implemented with “optional methods” in the interface?
Oct
4
comment Combinatorial explosion of interfaces: How many is too many?
@Dennis: One of the places where GC-based frameworks shine is in alleviating ownership issues for data which are never going to change. Object instances which can change need to have owners; those which aren't don't. I wish language/framework designers would recognize that RAII and GC each solve some problems easily that the other can do at best awkwardly, and thus combine the two approaches.
Oct
4
comment Is creating subclasses for specific instances a bad practice?
@millimoose: A base class should ensure that a derived class which abides by its inheritance contracts will abide by the base class's public contracts. In some cases it may be advantageous to add complexity in the base class to minimize the level of contractual obligations put onto a derived class; such efforts often make things more convenient for "leaf" classes [those with no descendants] at the expense of sub-derivable classes.
Oct
3
comment Do we need to test 32-bit software in 64-bit Windows?
@Thebluefish: Right. My point related to some experience with an application that contained two programs, one of which is .NET and the other of which is written using an x86-only development system, if the .NET one wasn't compiled for x86 only, it wouldn't see the registry keys set by the other.
Oct
3
comment Do we need to test 32-bit software in 64-bit Windows?
@gbjbaanb: The issue isn't just with DLLs. If a software package has some applications that are 32-bit only and some that aren't, x64 apps won't be able to see registry keys written by the 32-bit apps and vice versa (any idea why MS deliberately broke x86/x64 interop?).
Oct
3
comment Do we need to test 32-bit software in 64-bit Windows?
@Thebluefish: Given Microsoft's bizarre decision to have 32-bit applications effectively use a different registry from 64-bit ones, any package which uses a mixture of 32-bit and 64-bit programs that need to interact with each other is likely to have problems (and needs to be tested for them) on 64-bit machines.