3,356 reputation
514
bio website
location Illinois
age 45
visits member for 2 years, 8 months
seen 12 hours ago

17h
answered What are the safety benefits of a type system?
2d
comment Does code generation increase the code quality?
...instruction rather than an xor-immediate.
2d
comment Does code generation increase the code quality?
@MarkJ: Sometimes assembly can actually be better than a compiled language for uniformity. For example, in some embedded systems it's useful to be able to code the equivalent of x=someValue ^ 0xFF ^ 0xFF ^ 0xFF ^ 0xFF; and have it be coded with four XOR-literal instructions. If the code storage medium can only write blank (0xFF) bytes, the above construct will allow four arbitrary changes to the value. Even if one rewrote the expression as x=someValue; x = x ^ 0xFF ^ 0xFF ^ 0xFF ^ 0xFF; and compiler evaluated all the xors at runtime, it might still use a "complement all bits"...
2d
comment Does code generation increase the code quality?
...also update the source code to match the semantics of the hand-edited object code.
2d
comment Does code generation increase the code quality?
@anon: Homans should not generally edit the output of code generators or compilers, but it can sometimes be perfectly reasonable to have a build process which entails running one piece of machine-generated code through a program which applies some modification to it. There are also occasions when it may be necessary to have a human hand-edit the output of a build process if it is necessary to patch fielded code while changing a minimal number of bytes, but when code is tweaked by hand in such fashion one should also archive all files from the build process (not just source!) and...
2d
comment Why do programming languages, especially C, use curly braces and not square ones?
On many older teletype/terminal keyboards which didn't use a character-translation ROM, braces were regarded as "lowercase" brackets [often, the capslock key would map characters 0x60-0x7F to 0x40-0x5F; the shift key would map 0x20-0x2F to 0x30-0x3F, 0x30-0x3F to 0x20-0x2F, and 0x60-0x7F to 0x40-0x5F].
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?