Brian Tkatch wrote:Java may have its quirks, but they prove nothing.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Winston Gutkowski wrote:
Now it that doesn't convince you, nothing will.
Brian Tkatch wrote:I understand that arrays are objects (though, a working understanding is beyond my current knowledge.) Regardless, that's an implementation detail...
Arrays, in the theory, are not objects.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Winston Gutkowski wrote:What theory?
Brian Tkatch wrote:Might i ask this sub-thread be split from the rest (and then this remark removed)? IMO, it has nothing to do with it and does not belong in the current forum, though the original thread does.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Brian Tkatch wrote:Variables don't exist. They are simply (strictly typed) named memory locations used for convenience and to ward off errors due to mistaken use.
Regardless of how variables are typed (i.e. supported by the language), ultimately, the compiler (or runtime) knows what to expect in the memory location.
That is, x bits or bytes are the desired datum.
An array is different as we need two numbers. One, like before, how long each individual datum is, and two, how many of them there are. In some cases both numbers are recorded (where that is varies by language), in others, the array length is not recorded, but a stop byte is used (like C's string table where each string ends with a null byte.) Some, don't bother recording the length at all, and instead treat each individual array datum as a separate variable. So, the variable itself is actually an offset in the data segment, where the array offset (often, mistakenly called an index) if an offset from the start point. In either case, whether or not the length is stored, to retrieve an individual datum in the array, the offset is multiplied by the length of the type to find the starting point of the desired datum.
As it so happens, Java treats arrays as if they were objects. Ultimately, however, it makes no difference. It's just an implementation detail.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Brian Tkatch wrote:
Winston Gutkowski wrote:What theory?
Let's learn about variables! (Or, at least, my view of them.)
Variables don't exist. They are simply (strictly typed) named memory locations used for convenience and to ward off errors due to mistaken use.
Brian Tkatch wrote:Regardless of how variables are typed (i.e. supported by the language), ultimately, the compiler (or runtime) knows what to expect in the memory location. That is, x bits or bytes are the desired datum. Indeed, on the x86 processor, the variable is (the equivalent of, or is) an offset in the data segment which denotes where the datum starts, and the variable type (or the datum itself) defines how "long" the datum will be. The retrieval is stopped when reaching the allotted space.
Brian Tkatch wrote:As it so happens, Java treats arrays as if they were objects. Ultimately, however, it makes no difference. It's just an implementation detail.
Brian Tkatch wrote:Variables don't exist. They are simply (strictly typed) named memory locations used for convenience and to ward off errors due to mistaken use.
That sounds oxymoronic to me. If they don't exist, then how can they possibly have a name?
Regardless of how variables are typed (i.e. supported by the language), ultimately, the compiler (or runtime) knows what to expect in the memory location.
Largely true for a language like Java, but not for C, where it might be a void* returned, for example, by a malloc() call, and certainly not true of assembler where it can contain virtually anything, including another memory address.
That is, x bits or bytes are the desired datum.
And that is certainly not true of Java. Item 2.7 of the JLS clearly states:
"The Java Virtual Machine does not mandate any particular internal structure for objects."
And as a description of what an array is in C, that sounds pretty reasonable; but for a Java array it makes far too many assumptions.
the whole ethos of Object-Orientation is that I, as a user, don't need to know how an object works. I only need to know what it does.
And what I know about a Java array is that it is a fixed-length list of items, each of which is uniquely identified by an index (note: not an offset), and that it has a length that I can access via its length attribute.
Furthermore, Java is used in all sorts of situations, including ones that might not lend themselves to the implementation (and what you described above IS an implementation) like C's. Take for example, a temperature gauge in a greenhouse that has to record thousands of readings an hour. It might consist of a chip with a JVM burnt into it and a small amount (lets say a few Mb) of RAM connected to a disk drive or SD card that it can use as storage. Should an array then be contiguous memory? What if I want to access element #217234675 (well within the limits of a Java array index)? Should the whole thing blow up because it doesn't have enough memory to get the resulting offset?
Wouldn't it make more sense to implement Java's array as something more like a piece of virtual memory, divided into 64K chunks? I want element #217234675, which I know lies in chunk # (217234675 >> 16), so first I check my little cache to see if it's already loaded in RAM. If not, I go to the disk and read it into RAM, replacing the "oldest" chunk (assuming they're arranged as an LRU cache). And then I do what you describe above, except with an index of (217234675 & 65536).
Paul Clapham wrote:your post sometimes descends into word salad like for example "it is the variable that is arrayed, not the type". With vague and sloppy language like that you can wave your hands and assert anything. Arrays exist -- at least insofar as any concept can be said to "exist" -- but there's nothing being "arrayed".
Mike. J. Thompson wrote:In java, String[] is the type, not String. I imagine Java only allows the brackets in other places to make it familiar to C/C++ programmers.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Agree. I think I shall have to get a few whips out and drive some dogies in the direction of the previous posters who have gone to so much effort to answer.Brian Tkatch wrote:Thank you for the detailed reply.
. . .
That is simply an implementation detail which has no bearing on the higher‑level language. And Java® is not a compiled language.In a compiled language, variables are replaced with offsets. . . .
That is an implementation detail which varies from compiler to compiler. The older C compilers would compile a String to a *char which has no indication of its length at all. It simply continues until a \0 (=null) char is encountered. In fact older C/C++ compilers kept no record of the length of any arrays.. . . Once a memory location is set aside for use, either it or the runtime has a listing of its length. . . .
You are on very dubious ground saying that all, or even most languages maintain arrays the way that C does. There is no theory to go with it at all, otherwise all languages would do it the same way. Since there is no internal structure mandated for a Java® array, what you are describing are implementation details which do not concern us. The index shown when you write a Java® array is neither an index showing you that you are at a particular memory location nor an offset (as it would be in C). It is an instruction to the array which is an object to find the (n − 1)th element, designed to look like C‑style offsets.. . . This is not just C. Most--if not all--languages do it this way. That is exactly the theory i speak of. . . .
Agree. But I think you don't mean semantics, but syntax.Winston Gutkowski wrote: . . . I'm pretty sure that Mike's right, and the only reason Java's gurus chose to implement array semantics the way they did was for familiarity. . . .
Campbell Ritchie wrote:Agree. But I think you don't mean semantics, but syntax.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
// this form is discouraged
float anArrayOfFloats[];
However, convention discourages this form; the brackets identify the array type and should appear with the type designation.
Brian Tkatch wrote:Sheesh, all this for stating a preference!
While i disagree for the reasons i have already stated, i am really enjoying reading the posts here. I think i'm learning from that too!
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Campbell Ritchie wrote:And we are learning by disagreeing with you
The Java™ Tutorials does say// this form is discouraged
float anArrayOfFloats[];
However, convention discourages this form; the brackets identify the array type and should appear with the type designation.
Winston Gutkowski wrote:I'm wondering what languages you've used? Your assumptions seem to be very C-centric
A phrase familiar to anybody who has watched movies from the 1930s. But not correct, normal, English grammar. If you want to talk to everybody else, you have to talk the language they talk, and if you want them to understand you, you have to talk the way they talk. If you insist on talking differently, you cannot blame others if they don't understand you.With this ring, I thee wed.
Brian Tkatch wrote:Let's see, REXX, VX-REXX, SQL, t-sql, PL/SQL, PL/1, assembly, perl, bash, and a few others here and there...
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Campbell Ritchie wrote:
A phrase familiar to anybody who has watched movies from the 1930s. But not correct, normal, English grammar. If you want to talk to everybody else, you have to talk the language they talk, and if you want them to understand you, you have to talk the way they talk. If you insist on talking differently, you cannot blame others if they don't understand you.With this ring, I thee wed.
I'm thinking about a new battle cry. Maybe "Not in the face! Not in the face!" Any thoughts tiny ad?
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
|