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

Jul
20
comment Blocks of Javascript in Web Pages
Splitting off large scripts which would be shared among many pages would certainly seem helpful. If a piece of JS only makes sense in the context of a particular page, however, would browsers still benefit by having it as separate files?
Jul
20
comment Does javascript support numerically indexed arrays with a more optimized algorithm than an associative array?
Is it specified that slice() will copy all items with whole-number indices, and nothing else? I've noticed that calling slice on a very sparse array containing only a few elements can be very slow. If a non-array object is constructed which uses an array as a prototype, calling slice seems to include any whole-number-indexed items from the non-array object. I don't think there's any way to make an array which has anything else as a prototype, but I don't really know.
Jul
20
comment Does javascript support numerically indexed arrays with a more optimized algorithm than an associative array?
From what I can tell, an array in JavaScript seems to be a combination of an object and a linear array. Whole-number keys get stored in the array, and everything else gets stored in the object. If one adds various things to an array in random order and then uses for, it will list out all the whole-number subscripts first, in numerical order, followed by everything else in the order added (including fractional numbers).
Jul
20
comment Why do we still use JavaScript?
@JasonBunting: There's nothing wrong with type coercion in cases where it's clearly and unambiguously going to occur. If a language used $ as a string concatenation operator which was defined as coercing operands to strings, then I would have no problem with it allowing "count=" $ it.count without requiring it.count to be explicitly converted to a string. On the other hand, the fact that one cannot tell whether x+y will coerce either operand to string without knowing the operand types is, IMHO, a sign of dubious design.
Jul
20
comment What are the key differences between Java's and Python's OOP support?
...even though the ArrayList itself would perfectly happily accept a Dog. Note that the compiler allows code to bypass such type verification, by passing an ArrayList<Cat> to a method which accepts an ArrayList and adds a Dog, and in such cases code which passes list items to a method requiring Cat might fail at run time, but the point is that Java can reject at compile time most efforts to add a Dog to a collection of Cat, while Python has no such compile-time checks.
Jul
20
comment What are the key differences between Java's and Python's OOP support?
@kojiro: You are correct that Python doesn't have a fixed-sized array type analogous to Java's, and Java's closest equivalent is an ArrayList which is untyped from a run-time perspective. Even collections which are untyped from a run-time perspective, however, generally support compile-time checking; if one tells the compiler that a an ArrayList is supposed to contain only Cat, the compiler will allow items from the list to be passed to code which requires Cat without a manual typecast, but will reject an attempt to add an Animal into the list without a manual typecast...
Jul
19
answered What are the key differences between Java's and Python's OOP support?
Jul
18
comment Should I use extern global variables or static global variables with “get” and “set” functions in C
...might have to also ensure that the interrupt is running).
Jul
18
comment Consistency of an object
@sbi: I forgot to mention "add a layer of indirection"; sometimes it's necessary to have a class object which holds one value, exactly like the Thing class the article complains about. IMHO, the .NET Framework should have included something like public class SimpleHolder<T> {public T Value;} for such purposes. Use of get/set methods would be a bit silly, but encapsulating Value into its own object may be useful in a variety of circumstances, since a SimpleHolder<T> will have mutable reference semantics even if Value is a value type or immutable class type.
Jul
18
comment Should I use extern global variables or static global variables with “get” and “set” functions in C
@RobertHarvey: Validation logic can be difficult in C, since there's no exception-throwing mechanism to employ if validation fails. A more useful example in C might be update notifications. For example, in one version of a system, it may be possible to make something happen by writing a volatile variable (which e.g. gets polled in an interrupt routine that runs 60 times/second); a future version of the system, however, might require that code do something else to trigger that action (e.g. if it disables the interrupt when there's nothing for it to do, code which changes the variable...
Jul
18
comment What's the benefit of object-oriented programming over procedural programming?
...can be made much easier if when one writes MyMonstor-> the editor only shows a list of methods that are applicable to things of type Monster. If there are many dozens of different kinds of things, each of which supports about dozen operations, cutting the amount of clutter in the method lists by 90% can greatly ease productivity.
Jul
18
comment What's the benefit of object-oriented programming over procedural programming?
The concept of interfaces is not unique to object-oriented languages. A bigger factor, I think, is that in non-OOP languages nearly all the functions used within a module must belong to the same global namespace. This requires that one either prefix function names to indicate what they act upon, or else have many similar-sounding methods which do entirely different things (e.g. SetLocation might be used to move a Monster, while SetPosition might move a PopupWindow, and Move might be used to adjust the position of a DisplayCursor). Trying to find the right "move" method...
Jul
16
answered Static vs. non-static? (with non-OOP functions)
Jul
16
comment Has Little Endian won?
@stonemetal: By what mechanism can the JVM convert a sequence of one data type to/from a longer/shorter data type? I am unaware of any JVM instructions that would allow code to interpret elements 8-11 of a byte[] as an int, or store an int into four consecutive elements of a byte[]. A library might include methods to perform such conversions for big-endian but not little-endian format, but I would think that would be a property of the library rather than the JVM. Does the JVM offer anything internally?
Jul
15
comment Has Little Endian won?
@stonemetal: In what way would JVM allow endianness to matter, given that code which tries to read half of a long as an int will be rejected, and code which tries to write half of a long as an int will only be accepted if no attempt is made to read the long afterward.
Jul
15
comment Which is better: a bunch of getters or 1 method with a selection string parameter?
An advantage of using a command selector is that one can have an implementation that receives a command it doesn't understand call a static helper method provided with the interface. If the command represents something that can be done with nearly all implementations using a general-purpose approach, but which some implementations might be able to do via better means [consider e.g. IEnumerable<T>.Count], such an approach may allow code to enjoy the performance benefits of new interface features when using implementations that support them, but stay compatible with old implementations.
Jul
15
comment When to stop inheritance?
Even if one is trying to produce an AI engine, that doesn't necessarily mean one wants to only support "traditional" chess. If one may want to add in some additional pieces and moves (e.g. "grasshoppers"), a freer-form engine may be helpful. It won't be able to perform as detailed an analysis in a given length of time as could a faster engine, but most such chess variants are more about "fun" than serious study.
Jul
15
comment Should the methods of a class call its own getters and setters?
@Michael: There can often be good reasons for a class to not use its own getters/setters. One common scenario is where there are many setters of the form someField=newValue; refresh(); If method allows multiple fields to be set, calling setters to write those fields would cause redundant "refresh" operations. Writing all fields and then calling refresh() once may yield more efficient and smoother-looking operation.
Jul
15
comment Should consistency be favoured over programming convention?
Re-supplying the same item should generally be illegal unless the object is immutable, doesn't actually hold any resources, and doesn't care if it's disposed. For example, if Dispose requests were ignored for system brushes, a "color.CreateBrush` method might at its leisure either create a new brush (which would require disposal) or return a system brush (which would ignore disposal). The simplest way to prevent reuse of an object if it cares about disposal, but allow reuse if it doesn't, is to dispose it.
Jul
15
comment Should consistency be favoured over programming convention?
As a further extension of the handOff pattern, if such a property is set in the constructor, but another method exists to modify it, that other method should also accept a handOff flag. If handOff was specified for the presently-held item, it should be disposed, then the new item should be accepted and the internal handOff flag updated to reflect the new item's status. The method shouldn't need to check the old and new references for equality, since if the original reference was "handed off" all references held by the original caller should be abandoned.