3,384 reputation
514
bio website
location Illinois
age 45
visits member for 2 years, 9 months
seen 2 hours ago

Apr
7
comment How much work should I place inside a lock statement?
On the flip side, holding a lock while undertaking a task that may require acquiring another lock can cause a deadlock that can hardly be termed "correct" behavior. One should ensure that all code which needs to be done as a unit is surrounded by a common lock, but one should move outside that lock things that don't need to be part of that unit, especially things that may require acquisition of other locks.
Apr
7
comment When there's no TCO, when to worry about blowing the stack?
@Ingo: A word-counting program doesn't assume there are no memory limits; rather, it assumes the total length of the distinct words in the input file will be small enough not to exceed the memory limits. By contrast, a parser state machine implementation that uses tail call to progress from state to state would be able to handle input files of arbitrary size but finite nesting using a finite amount of stack, but bomb on input files over 1500 tokens on a JVM which doesn't support TCO but has a 64KB stack.
Apr
7
comment When there's no TCO, when to worry about blowing the stack?
@Ingo: A program's use of bounded or unbounded resources should be a conscious design decision. If a program can recognize whether a resource is bounded or not, and vary the size of problem it will accept accordingly, that's fine. What's generally not fine is running a program that assumes a particular resource is unbounded, on systems where it's not, especially if the program is ill-equipped to handle its scarcity.
Apr
7
comment When there's no TCO, when to worry about blowing the stack?
@Ingo: If a piece of code can handle 500,000 records on the old JVM but a new JVM which increased that limit to 1,000,000, having the code still run on the old JVM would be a good thing. If, however, code written for the new JVM could handle 1,000,000 records but on the old JVM it would die if given more than 213, having the code be "compatible" with the old JVM may not be such a good thing. I would think the best way to go would be to have it be a new language feature and specify that code which uses it will require the new compiler and JVM.
Apr
7
comment S.O.L.I.D., avoiding anemic domains, dependency injection?
...get recorded from a fictitious "Unowned vehicle tax credit" person, so that as of the time of sale the tax liability will be either zero or thirty days, regardless of how long the vehicle had been unowned.
Apr
7
comment S.O.L.I.D., avoiding anemic domains, dependency injection?
I think the vehicle itself should record the taxes paid for it, and individuals should record taxes paid for all their vehicles. A tax code could be written so that if the tax on a car is paid June 1 and it is sold on June 10, the new owner might become liable for the tax on June 10, July 1, or July 10 (and even if it's presently one way it could change). If the 30-day rule is constant for the car even through ownership changes, but cars that are owed by nobody can't pay taxes, then I would suggest that when a car which had been unowned for 30 or more days is purchased, a tax payment...
Apr
7
comment When there's no TCO, when to worry about blowing the stack?
@Ingo: The proper way to support tail-call invocation would be with a special "tail return" syntax, which would inform the compiler that tail-call invocation is semantically required. While a compiler could easily identify cases where tail-call invocation could work (if code doesn't happen to care about stack traces) code which relies upon it but doesn't specify it would be brittle, since a change which precluded that optimization wouldn't generate an error but would yield code which would crash with large data sets (but still work with small ones).
Apr
6
comment OO Software Architecture - base class that everything inherits from. Bad/good idea?
@DocBrown: According to the ECMA spec, when the Runtime sees a class derived from ValueType, it actually defines two kinds of thing: (1) a heap object type which behaves like a class which derives from ValueType and thus object; (2) a storage-location type which holds neither an object nor a reference to one. Given int x=32; object y=x; variable x will be a 32-bit word holding bit pattern 0x00000020, and y will hold a reference to a heap object of type Int32 which contains, among other things, the bit pattern 0x00000020. The latter derives from Object; the former does not.
Apr
6
comment Is there a specific name for the “Square inherits from Rectangle” paradox?
@JörgWMittag: I don't think I'd heard that rule; how would it apply if a derivative of ImmutableRectangle offered a mutable Color property? My instinct would be that a typical base contract should forbid such a thing, but the basis should be an equals contract that promises that if x.equals(y) is true, then members of the class itself should not be able to distinguish x from y (the class itself has no way to prevent outside code from testing reference equality). How would the History Constraint deal with that?
Apr
6
comment When there's no TCO, when to worry about blowing the stack?
@Ingo: If a function only recurses with itself, the stack trace may not show much. If, however, a group of functions are mutally recursive, then a stack trace may sometimes show a great deal.
Apr
6
comment When there's no TCO, when to worry about blowing the stack?
If a tail-call opcode existed, why would tail-call optimization require anything other than observing at each call site whether the method making the call would need to execute any code afterward? It may be that in some cases a statement like return foo(123); could be better executed by in-lining foo than by generating code to manipulate the stack and perform a jump, but I don't see why tail-call would be any different from an ordinary call in that regard.
Apr
6
comment Should HTTP Request/Response objects be immutable?
@Philipp: IMHO, one of the biggest deficiencies in Java.NET is the lack of a convention to distinguish between methods that return references to new objects that the caller can change at will, versus those which return references which are attached to or encapsulate internal state that may be modified to manipulate that state, and those which return references to object which may or may be attached to internal state. It's not possible to write code that is robust and efficient without knowing what sorts of references things are supposed to return, but there's no convention to indicate that.
Apr
6
comment what is the difference between callbacks and listeners?
It may also be relevant to say that callbacks are often passed to the action which would create the need for them. In many cases, the caller wouldn't "connect" a callback, but rather pass it to a method whose job is, e.g. "Request some data from a remote system, and invoke a caller-supplied method when a response is received or an error occurs". Outside code doesn't generally "connect" a callback; rather, the called code is responsible for establishing the connection to the passed-in method.
Apr
6
comment What is the difference in memory between a variable assigned to null and one not assigned
From a bytecode perspective, local variables are allocated on the stack. The JITter, however, may decide decide that a particular stack entry shouldn't actually be stored on the stack, but stores to and loads from that entry should be directed at a particular CPU register. Further, if the JITter determines that once execution reaches a certain point there's no way a stack entry will be read without having been rewritten, it may reassign that entry's associated register for some other purpose.
Apr
2
comment Is it a bad practice to separate the unit tests for a class?
I would not consider it at all unreasonable for a class to have more than twenty utility methods if there are that many common sequences of operations which a lot of clients will do. If 10% or more of clients are likely to perform on instances of a class a particular sequence of operations that requires no outside dependencies, I would consider that a hint that the class should perhaps include a method to do such operations on itself; I don't see why the fact that a class already has 19 methods should dissuade one from adding a 20th which would serve such a purpose.
Apr
1
comment Why does Cem Kaner consider a test not revealing a bug a waste of time?
@JonHanna: My phrasing was poor: the issue isn't expectation, but effort. One can't prove a theory by trying to find tests it will pass; one must make a bona fide effort to find tests which it would fail if invalid.
Mar
31
comment Why are people making tables with divs?
@rooby: Is there any nice way to format a side-by-side translation in a manner that will permit either side to be read or copied in top-down order, but will can also add blank space on either side as needed to keep a correspondence between things on the left and right side that word-wrap differently?
Mar
30
comment Why does Cem Kaner consider a test not revealing a bug a waste of time?
Your quote reminds me of something I've observed about science: one can't prove (or even meaningfully support) a scientific theory by conducting experiments one expect to yield results consistent with the theory; the way to support a theory is to make a bona fide effort to device experiments that won't support it, but being unable to do so.
Mar
28
answered What are the safety benefits of a type system?
Mar
26
comment Does code generation increase the code quality?
...instruction rather than an xor-immediate.