2,513 reputation
411
bio website
location Illinois
age 44
visits member for 2 years, 5 months
seen 35 mins ago

30m
comment What are the valid uses of static classes?
I wish frameworks provided somewhat better support for thread-static state, rather than viewing it as an afterthought. Something like Console really shouldn't be part of the system-wide state, but nor should it be part of an object that gets passed around constantly. Instead, it would seem like it would make more sense to say that each thread has a "current console" property which can be easily saved and restored if it's necessary to have a routine which writes to Console use something else instead.
1h
comment Are all magic numbers created the same?
@GlenH7: IMHO, the power-of-two-based units should have been kept for storage, since it's allocated in power-of-two sized chunks. It the minimum allocation size is 4096 bytes, does it make more sense to have a unit for the amount of storage required to hold 256 minimal-size files, or the amount of storage required to hold 244.140625 such files? Personally, I view the difference between hard-drive-maker megabytes and other megabytes to be analogous to the difference between television set diagonal inches and real diagonal inches.
8h
comment Is it poor practice to call methods through multiple objects?
@pdr: ...I would interpret LOD as saying one should avoid using more than one -> in an expression, or avoid using -> on a reference (or portion the object identified thereby) which was itself received via ->. BTW, having such a distinction in the language would allow clone, equals, and hashCode() methods to be 99% automated.
8h
comment Is it poor practice to call methods through multiple objects?
@pdr: Feel free. IMHO one of the great weaknesses of Java is that it only has one type of reference and does not distinguish whether any given reference encapsulates identity, mutable state, both, or neither. While it would be excessively expensive for a framework to support C++'s full litany of copy constructors etc. I think a good language should distinguish between fields which identify things whose state is part of that of the object holding the field, versus those which identify things whose state is owned by someone else. If the language used . for one and -> for the other, then...
1d
comment Is it poor practice to call methods through multiple objects?
@pdr: Indeed. Without knowing what the nature of tr, I can't really say whether tr.t should be considered part of tr, or whether it should be considered part of whatever holds the reference to tr. While the type of tr may be somewhat relevant, I think a bigger issue is how it's used. IMHO, the biggest problem which LOD tries to prevent could be covered by a rule that says that sharable objects which encapsulate their state in mutable objects should not expose those objects, and objects which encapsulate state in exposed mutable object should not be shared.
1d
answered Why convert to assembly language instead of machine code?
1d
comment Is it poor practice to call methods through multiple objects?
@pdr: By my understanding of LoD, it would suggest that rather than asking the list for element 0, and asking the returned item its color, one should ask the list for the color of element 0. The problem with that concept is that the list has no idea what a Car or a Color is. All it knows is that it holds a reference to Object #592. A class which encapsulated the states of many cars, and allowed client code to examine or manipulate them without exposing references, could be more safely shareable than List<Car>, but unless it needs to be shared would not be worth the trouble to code.
1d
comment Is it poor practice to call methods through multiple objects?
@pdr: My my understanding, the main purpose of the Law of Demeter is to ensure that any change to some aspect of an object's state should go through the object in question. If a List<Car> holds one element--a reference to the 592nd object created since startup, which is a Car whose Color is "blue", then the state encapsulated by that List<Car> is the fact that item #0 holds a reference to Object #592. Code which owns the List<Car> might care about the fact that Object #592 has a Color of "blue", but that information is not part of the state of the List<Car>.
2d
comment Is it good practice to inherit from generic types?
If a type extends another without adding anything, references of the latter type will only be able to identify instances of that type. For example, if one were to define IImmutableEnumerable<T> : IEnumerable<T>, and all immutable enumerable types one was interested implemented that interface, then code which wants an enumerable sequence which can be guaranteed not to always return the same sequence of values could use a parameter of type IImmutableEnumerable<T>. Such an interface wouldn't add any new members, but that wouldn't prevent it from making new promises.
2d
comment Is it poor practice to call methods through multiple objects?
The linked article about LOD seems to ignore a fundamental issue: ownership. If a piece of code owns an object (typically by holding the only reference to it anywhere in the universe) and the object provides a place for its owner to store something, that place would be owned by the owner of the object containing it, and that owner would be entitled to use it just as it would one of its own fields.
2d
comment Is it bad coding practice to create something in a get if it does not exist?
I might suggest a fourth method: getAccountIfExists, which would either get an account or indicate that it doesn't exist without creating a new one. The getAccount method itself should presuppose that the account exists, and throw an exception if not.
2d
answered Are all magic numbers created the same?
Dec
11
comment Is there ever a reason to use an array when lists are available?
If one wishes to use a collection of mutable-object references as a collection of independent groups of independent variables, one must establish and maintain an invariant that each element identifies an object to which no other non-ephemeral references exist anywhere in the universe. That can certainly be done (and often is), but there is nothing in the language or framework to assist the programmer in upholding that invariant. By contrast, a length-100 array of a structure type with four instance fields will automatically and permanently encapsulate 400 independent variables.
Dec
10
answered Is there ever a reason to use an array when lists are available?
Dec
10
comment Is there ever a reason to use an array when lists are available?
If a type is supposed to represent a group of related-but-independent variables stuck together with duct tape (e.g. the coordinates of a point), an exposed-field struct is the best representation. If a variable is supposed to hold a bunch of such groups, an array of that structure type is the best representation. One shouldn't use mutable structs in places where one wants an object, but that doesn't mean one should use objects or things that pretend to be objects in places where one wants a bunch of variables stuck together with duct tape.
Dec
10
comment What is the best way to initialize a child's reference to its parent?
I would use a slightly-looser definition of aggregate, which would allow for the existence of outside references into parts of the aggregate other than the root, provided that--from the point of view of an outside observer--the behavior would be consistent with every part of the aggregate holding only a reference to the root and not to any other part. To my mind, the key principle is that each mutable object should have one owner; an aggregate is a collection of objects which are all owned by a single object (the "aggregate root"), which should know of all references that exist to its parts.
Dec
10
comment What is the best way to initialize a child's reference to its parent?
...to have it be visible in an aggregate root object which owns all the others, than to have it be hidden among all the objects in the forest. If an aggregate root "knows" about all dependencies among the objects within the aggregate, such dependencies may be unraveled by focusing on the aggregate root. If some objects can have dependencies the aggregate root doesn't know about, unraveling such dependencies will require examining all such objects--generally a much larger task.
Dec
10
comment What is the best way to initialize a child's reference to its parent?
@Neil: If the domain includes a forest objects with irreducible cyclic data dependencies, any model of the domain will do so as well. In many cases this will further imply that the forest will behave as a single giant object whether one wants it to or not. The aggregate pattern serves to concentrate the complexity of the forest into a single class object called the Aggregate Root. Depending upon the complexity of the domain being modeled, that aggregate root may get somewhat large and unwieldy, but if complexity is unavoidable (as is the case with some domains) it's better...
Dec
9
comment What principle of OOAD is this pattern breaking?
I hadn't seen the phrase "Common Closure Principle" before; I think I tend to think it would be more important to have things that may need to be changed together share an assembly than to have things that aren't be changed together in separate assemblies. If classes Foo and Bar are in separate assemblies, that creates the possibility that a new version of Foo might try to run with an old version of Bar, or vice versa. If they're in the same assembly, such a thing simply can't happen.
Dec
9
answered Trying to identify IClass, Class, ClassImpl pattern