• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Pointless semantics or important?

 
Ranch Hand
Posts: 212
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The JLS calls this: int[][] an array of arrays, even though it also refers to it as a 2D array. I think about it as a 2D array or matrix because traversals through an array of arrays is exactly as you would expect traversing across a 2D matrix.

I usually consider stuff like this to be like the tomato pronunciation argument. This weekend I was working on a distributed multiprocessing project in C, where I am using a 2D char array, which is actually a dynamically allocated array of pointers to arrays of chars. Anyway, it just got me thinking about how many times I have read someone on these and other Java boards refer to a 2D array only to get corrected semantically.

The reason this bothers me is that Sun, for better or worse, decided to hide memory details and the almost always refer to elements of the language and API in more abstract terms. Memory details are irrelevant, yet when it comes to this, a proper description of what is going on in memory is seen as more appropriate to a more abstract term that describes its behavior.

Does it really matter?
[ June 04, 2007: Message edited by: David McCombs ]
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would say it does matter. As you know, the array-of-pointers-to-char is like Java's "2D arrays", but C also has another kind of 2D array, the "real" kind: a contiguous block of memory, where you do a little computation involving both the row and column number to get the offset into the block for each element.

In the case of arrays, Sun didn't hide all the details; there are things you can do with the ptr-to-ptrs kind of matrix that you just cant do with the other kind, and vice versa. If you think of it as a 2D array, then the ptr-to-ptrs manipulations don't seem obvious, even though they're common things to do. For example, the Java kind doesn't have to be rectangular, while "real" 2D arrays do. The Java kind can be dynamically allocated in both dimensions, and can "grow" (by copying and reallocating) at runtime in either dimension, while the "real" kind has at least one dimension permanently fixed at compile time.
 
David McCombs
Ranch Hand
Posts: 212
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your comments, I understand what you are saying and agree, It just seems like a semantic argument in most cases.

I guess I just haven't used them for anything more then basic purposes so it doesn't seem as important.
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It may seem silly for people who use Java only (or only other languages that don't have true multidimensional arrays). But for people who also use languages that do have both types of arrays, it's useful to keep the two types straight, and preferable to use consistent terminology even when programming in Java.

There's a similar issue between passing by reference, and passing a reference by value. To Java-only programmers these sound like the same thing, because Java does not support true pass by reference. But to people who use other languages that do support it, it's an important distinction.
 
David McCombs
Ranch Hand
Posts: 212
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I agree with the importance of the pass by reference/value issue. I have no problem keeping that straight, even when pass by value behaves like pass by reference. I think the usage of the "phrase passing a reference to x" is the root of the confusion.

I will read up more on the gory details of 2D arrays and array of arrays.

Thanks for the input.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic