3,394 reputation
514
bio website
location Illinois
age 45
visits member for 2 years, 9 months
seen yesterday

Mar
25
comment Why did programming languages start using = for assignment?
@COMEFROM: If y∈ℤ and z∈ℤ, the shorthand "let x=yz" could be interpreted to say "let x∈ℤ such that x=yz", or "let x∈ℝ such that x=yz", etc. or any other ring to which y and z belong, and all such statements would be equivalent. No such equivalence would exist for e.g. "let yz=6". Should such a statement be assumed to allow (y=-2 z=-3)? Or (y=1.5 z=4)? How about (y=2i z=-3i)? Unless the meaning is made clear in context, the statement "let yz=6" is insufficient to define a set of (y,z) tuples.
Mar
25
comment Is there a reason to have a bottom type in a programming language?
...would make C a usable language for writing portable code. As it is, I think standard writers have historically been more interested in writing a standard which would allow obscure systems to implement a language and call it "C", than in defining one which would allow code written in C to run identically on an 8-bit micro or a 64-bit monster.
Mar
25
comment Is there a reason to have a bottom type in a programming language?
@MarcvanLeeuwen: I can see how that could be somewhat useful, though the lack of such a type is far less of an omission IMHO than the inability to distinguish between e.g. 16-bit values which are used as a wrapping algebraic rings (such that given uint16_t a=2,b=65535; uint32_t c=0; the expression c+=(a-b); would add 3 to c), or as numbers (such that the expression would subtract 65533 from c). Even if different processors have different integer sizes that are "most convenient" to work with, allowing code which needs particular integer behaviors to specify them...
Mar
24
comment Why did programming languages start using = for assignment?
@COMEFROM: In mathematics, the statement "let x=yz" defines a new free constrained variable "x". What would would "let yz=x" mean? How about "let yz=wx"?
Mar
24
comment Is there a reason to have a bottom type in a programming language?
So is the idea that var foo = someCondition() ? functionReturningBar() : functionThatAlwaysThrows() could infer the type of foo as Bar, since the expression could never yield anything else?
Mar
23
answered Why is the hashCode method usage of HashSet not specified in the API?
Mar
20
comment What is the name of a function that takes no argument and returns nothing?
I might be inclined to use ProcedureRIR<T1,T2> for void proc(T1, int, T2), and likewise for other types--probably creating most of them on demand rather than trying to cram in every possible combination of types.
Mar
20
answered Is it better to use preprocessor directive or if(constant) statement?
Mar
20
comment Why does the Java collections APIs not have a last method?
I think a bigger answer is that Java's initial failure (repeated in .NET, and still ongoing in the latter case) to support default interface methods meant that having interfaces include a member which 99% of implementations would handle the same way would impose extra work on all implementations for the benefit of the few that would implement them differently.
Mar
20
comment Best and safest API for a function which fills a buffer with variable-length data
Another variation is to have several kinds of buffer (distinguishable by the first byte), and have a method which, given a pointer to any of them, will fill in a structure with a flag byte, current length, data pointer, and allocated length. Tiny buffers (e.g. 63 bytes or less) only need one byte of overhead; medium-length buffers (4K or less) need two, and larger ones need more.
Mar
20
comment Why do we have postfix increment?
IMHO, the times when the prefix/postfix distinction is helpful could conceptually be regarded as higher-level operators such as "derference and postincrement" or "decrement and check the result against zero". While I understand K&R's rationale for making individual pre/post inc/dec operators, rather than having composite operators, I think the operators make more sense as part of a composite operation.
Mar
20
comment Avoid Postfix Increment Operator
@Stephen: C++ means take C, add to it, and then use the old one.
Mar
19
comment Card deck and sparse matrix interview questions
That makes sense. If one was only having to evaluate five cards, one could find a straight other than ace-high, without the "concentrated" upper bits by computing v1 = v & 011111111111110000 on the "or" of all the cards to get the ranks info, then v2=v1 & ~(v1-1); to locate the LSB, v3 = (v1 | 066666666666660000) + v2; to process a carry chain, and v4=v1 & v3; to see if all bits were consecutive. I can see, though, that a lookup table would be helpful if one needs to see if any five cards out of seven would yield a straight, though I'd think concentrating lower bits would be better.
Mar
18
comment Card deck and sparse matrix interview questions
Are the upper bits used to determine if the card is a straight, or what's the intention? I can see that for up to seven card stud the lower bits will quickly tell you how many cards of each rank and suit there are; they could also pretty easily identify if there's a straight, though perhaps the upper bits are better for that?
Mar
18
comment Why not free memory as soon as its reference counter hits zero
...to limit the maximum size of any single GC object, and accept a little extra overhead on longer strings to facilitate such subdivision). There's no way a reference-counting collector would get its overhead that low.
Mar
18
comment Why not free memory as soon as its reference counter hits zero
Relocating tracing garbage collectors can operate under very tight memory constraints; while it's possible to design a relocating collector that keeps for each object a list of references to it, the overhead generally ends up being higher than for a tracing collector. On a machine with a 64K heap, one could have an efficient tracing collector store arrays of strings references at a cost of two bytes per string reference, and store string objects with an overhead of only one byte for short strings (e.g. under 64 bytes), and slightly more for longer ones (it may be helpful...
Mar
17
comment Why do you need higher kinds?
@itsbruce: Sorry I misunderstood the concept; I was not trying to be inflammatory. Based on what Doval says, it sounds as though what you're describing is something that I'd like to have be possible in interfaces with .NET (but which presently isn't)--basically say that for a class to be castable to an interface, either the class or the interface should have to want to allow the cast, and for each member of the interface an implementation must exist either in the class or in a spot designated by the interface. Does that sound like what you're after?
Mar
17
comment Why do you need higher kinds?
...there should exist a method void staticClassName<Goo>.Foo(Goo it, int p), and the JIT would add to the class Goo a method void InterfaceName.Foo(it) { staticClassName<Goo>.Foo(this, it);}. Making all that work efficiently might be a little tricky, but not too bad if one is willing to accept a slowdown in the unsuccessful-cast case [and even that could probably be optimized by keeping a table of unsuccessful casts that have been attempted].
Mar
17
comment Why do you need higher kinds?
@GregRos: That sounds like something I'd like to have in .NET: the ability for an interface to specify that if a type is cast to an interface it doesn't implement, the Runtime would check to see whether the interface has a metadata-specified generic class with a type parameter whose constraints would be specified by the type in question and, if so, whether that class contains all the static methods that would be necessary to build an implementation (e.g. if an interface has void Foo(int), then for class Goo to be castable to that interface...
Mar
17
comment Module system for OOP language
@AberKled: I don't think the issue is so much having the language be responsibility for "handling versions", as ensuring that if Fred has one version of module X when he writes a module Y that works with it, and Joe has a different version of X when he writes module Z that works with it, then in the absence of unresolvable behavioral differences between the different versions of X, it should be possible to use Y and Z together without having to recompile either.