1,536 reputation
39
bio website
location Illinois
age 44
visits member for 2 years
seen 1 hour ago

Jun
2
comment When do rounding problems become a real problem? Is the least significant digit being one off really a big deal?
@maaartinus: How do you handle division? Do you require that code specify the desired precision, use as much as possible but allow it to be dropped arbitrarily (so that 1/3 equals 0.333333333333333333 but 1/3+10000000000000000-10000000000000000 equals 0.33), or do you do something else?
Jun
2
comment Object Identity and Mutability
...cause thing to hold a reference to a boxed Cat that held a copy of the reference (to a SiameseCat) held in Fluffy. Note passing a variable holding null to such a method would pass a box of the proper type whose content was null, and would thus allow the method to know the type of the variable.
Jun
2
comment Object Identity and Mutability
@JanHudec: The ability to use structure types without having to worry about them accidentally acquiring an identity is helpful, though I wish .NET didn't try to pretend that structures were objects. It would IMHO have been more helpful to have a Box type which behaved as fixed-size single-element array, and allow method parameters to indicate that arguments should be boxed always, never, or only when needed [if a method specified "always", then if Fluffy is a variable of type Cat which identifies a PersianCat, then passing it to an always-box parameter thing would...
Jun
2
comment Object Identity and Mutability
@JanHudec: Integer is not a primitive type; it is a class whose instances contains a single final field of type int. As for everything being immutable, that is in a sense true, but it's more useful to "immutability" in such a way that classes like String and Integer can satisfy, than to regard such classes as no different from e.g. Point.
Jun
2
comment Object Identity and Mutability
@JanHudec: Semantically, no object can be more immutable than Object. Any definition of class-level immutability which would be satisfied by e.g. Integer would be equally satisfied by Object. Further, in general when an object is said to encapsulate mutable state, it's possible to meaningfully copy that state from one instance to another. I don't think there's any way of copying the lock state of one object to another.
Jun
2
comment Object Identity and Mutability
...that immutable instances which encapsulate the same state may be used interchangeably, but there's no way a type can guarantee that. If code uses new String("Hello"); as a key in an IdentityHashMap, the string would look like any other string encapsulating those characters to any code which didn't know of that map, but it wouldn't be substitutable because its underlying object would have an identity token that was different from every other object throughout the entire universe.
Jun
2
comment Object Identity and Mutability
@JanHudec: I would say monitor locks in Java and .NET as use Object as an identity token. To the extent that they are viewed as encapsulating mutable state in an object, there's no such thing as an immutable object. It's ironic that Java is sometimes viewed as a "teaching language", given that a more significant design goal was to simplify the runtime by using a single reference type; from a semantic perspective, it would have been better to distinguish types which have an identity from those which don't. The primary benefit of immutable types is...
May
29
comment “Collection Wrapper” pattern - is this common?
...whose particular type one doesn't recognize as promising immutability is to make a copy of it. Note that while many instances of ReadOnlyCollection<T> are immutable, the type offers no means by which an instance can indicate whether it's actually immutable or not. If code which needs an immutable sequence receives e.g. the return from Enumerable.Range(1,1000000), it shouldn't need to make a copy, but there is at present no way for the Enumerable.Range return to let it know that, especially if wrapped in a ReadOnlyCollection<int>.
May
29
comment “Collection Wrapper” pattern - is this common?
@Jules: IMHO, one of the major weaknesses which .NET still has not addressed in its collections is that none of the collection interfaces include a method to request an IEnumerable<T> which will always encapsulate the sequence of items the collection holds at the time of the request. An immutable collection could simply return a reference to itself; a mutable collection could copy itself to a new immutable collection. Such a feature would allow many copy operations to be safely elided. Unfortunately, without such a feature, the only way to encapsulate the sequence in an IEnumerable<T>....
May
28
comment “Collection Wrapper” pattern - is this common?
...e.g. a multitude of 256-item arrays to hold its contents, copying five batches of items to or from a 1,000-item temporary array would still likely be much faster than having to use 1,000 separate operations.
May
28
comment “Collection Wrapper” pattern - is this common?
@Jules: In many frameworks, copying e.g. 1,000 consecutive items from one array to another may be done in significantly less than half the time it would take to process 1,000 items individually. Thus, if one has two array-backed collections which know nothing about each other, exporting 1,000 items from the first to an array, and then having the second copy 1,000 items from that array, may be much faster than copying 1,000 items one at a time. Note that it the speed-up doesn't require that either collection hold its data using a single array; even if a collection used...
May
28
comment Builder Pattern: When to fail?
If e.g. one is building a Shape and the builder has WithLeft and WithRight properties, and one wishes to adjust a builder to construct an object in a different place, requiring that WithRight be called first when moving an object right, and WithLeft when moving it left, would add needless complexity compared with allowing WithLeft to set the left edge to the right of the old right edge provided that WithRight fixes the right edge before build is called.
May
28
comment Builder Pattern: When to fail?
It may be worth noting that if the validity of one parameter depends upon the value of another, one can only legitimately reject a parameter value if one knows that the other is "really" established. If it is permissible to set a parameter value multiple times [with the last setting taking precedence], then in some cases the most natural way to set up an object may be to set parameter X to a value which is invalid given the present value of Y, but before calling build() set Y to a value which would make X valid.
May
27
comment Why is the minimum value of ints, doubles, etc 1 farther from zero than the positive value?
It's not just bit manipulations. The set of 32-bit signed numbers is the set of numbers whose binary representation has the same value in all bits after the 31st, and one such number has an infinite set of ones followed by 31 zeroes. The additive inverse of that number, an infinite string of zeroes followed by a single 1 and 31 zeroes, does not fit the pattern required of signed values.
May
27
comment What is the gain from 64-bit architecture?
A file system is not RAM, and I'm not clear why one would want to address it as RAM. The only way to write a single byte on a flash drive is to read a sector into a buffer, modify the buffer, and then write it back. Even of one's OS was willing to do that, performance would be positively dreadful. Further, what would a "pointer" to a block of a file mean if the file were truncated or deleted?
May
27
comment Why are there so many numeric types (bit, int, float, double, long)?
I'd separate them differently: discrete numbers, approximate numbers, and wrapping algebraic rings. Typical examples in C would be int, float, and unsigned int, respectively. Fixed-point types are a subcategory of discrete types, but algebraic rings are fundamentally different from numbers [must of the confusion regarding unsigned types in C stems from the fact that they mostly behave like rings rather than numbers, but aren't quite consistent].
May
22
comment What is the responsibility or benefit of a Tokenizer?
@delnan: For some kinds of compilers, lexing (folding in dictionary lookup, assuming a global token table, so the remainder of the compiler works with integers rather than strings) can be a significant part of overall compilation speed [simply because the rest of the compiler doesn't have to do a while lot]. On other types, much more time is spent on graph coloring and other related optimizations.
May
22
comment What is the responsibility or benefit of a Tokenizer?
...and exposed two OneWriterMultiReaderAppendOnlyList objects--one of which held tokens and the other of which held token numbers [that would if positive identify things in the list, and if negative encapsulate either things like reserved words, etc. or pre-evaluated small numeric literals] such a design could perform quite well.
May
22
comment What is the responsibility or benefit of a Tokenizer?
@delnan: I haven't looked at how compilers are implemented these days, but I would not expect synchronization overhead to be particularly large in this sort of situation, especially in a runtime environment where variables written in one thread will "usually" be seen by another reasonably soon, and memory barriers would only be needed in cases where either the reader thread caught up to whatever it could see from the writer, or the writer got too far ahead of the reader. I would expect that if the tokenizer built a dictionary of all unique tokens received in a job...
May
16
comment Why do most programming languages not nest block comments?
I would suggest that if you want to allow nested comments, you allow start-comment tags to be marked with a token, and require that if a start-comment tag is thus marked, its end-comment tag must be marked identically. That would allow unbalanced start/end tags to be quickly identified, and avoid the possibility of bugs caused by undetected unbalanced tags.