4 ms·
In Java, you can store an object in an array and then modify that object in both the array copy and the one you have in a regular variable because Java works by
by mynameishere 18y ago
In Java, you can store an object in an array and then modify that object in both the array copy and the one you have in a regular variable because Java works by reference, not by copy.
LOL. In what language does array assignment result in a new copy of that data structure rather than a reference of it?
http://en.wikipedia.org/wiki/Array http://en.wikipedia.org/wiki/Array
In computer science an array[1] is a data structure consisting of a group of elements that are accessed by indexing.
Answer: None.
You'll get tripped up on a type mismatch error
Every real language has types. Java catches most errors at compile time. That's an advantage for students.
- mynameishere 18y agoI don't mind downmods on political subjects (too much), which are matters of opinion to a degree. But when I correct somebody's laughable mistakes, please either correct me in writing or leave it alone. Thanks.
- dcurtis 18y agoI am pretty sure it was your tone.
- mynameishere 18y agoJava is a whipping boy, and I also have my problems with it, but one of its minor strengths is that it is clean enough for a teaching language (especially for total neophytes). Here is the much lambasted manner of outputting: System.out.println("Hello world"); ...in fact, this is well organized. "System" is a namespace. "out" is a static variable. "println" is a static function. "Hello world" is a String. These things all exist in an orderly world. A professor could explain a lot of key elements of language design with that one line. What's this: print("Hello world") ...it's shorthand for much the same. Easier? Yep. But it's glossing over a lot of details that students need to know. So when you come at it from a teaching angle, you're maybe making a mistake. Python/Ruby/LISP all have their WTFs that will throw off students, even if they're all better languages than Java.
- gnaritas 18y agoJava's a horrible language for teaching. If you think this... System.out.println("Hello world"); Is easier to understand than this... print("Hello world") Then you've forgotten what it's like to be a beginner. Java's not even a good example of what OO is, and it has way too much syntax and special keywords (something like 50) for teaching. Python is a far better language for teaching, Smalltalk would be even better because it's much simpler, has only a handful of keywords, and a much more consistent and simpler syntax. In any case, students should begins with a dynamic language where they don't have to think about manifest types that they aren't ready to understand anyway. It's also much faster working in a workspace or REPL where you have instant feedback and can experiment without messing around with compilers.
- pg 18y agoThen you've forgotten what it's like to be a beginner. Not just that, but what programming should be like. Hello-world shouldn't need more than two elements.
- gnaritas 18y agoI think some people just forget that the machine should be working for the human rather than vice versa.
- axod 18y agoI think judging a language by "Hello-world" is a mistake. Sure, some languages have a fixed overhead for creating a program. Some have needless syntax fluff that doesn't do all that much, but it's actually a good skill IMHO to be able to identify and see through that fluff to the core elements of the code. When we pick up a book do we judge it based on the index at the back and the preface and the publishing info at the start? We probably just ignore those bits. I think in these sorts of classes it'd actually be a good idea to spend several weeks looking at other peoples code and analyzing what it does. Being able to read code properly is a really important skill I think people should master before they even start with writing hello-world themselves.
- kragen 18y agoIn Pascal, Ada, PL/1, Perl, and C, array assignment or passing an array as a parameter results in a new copy of the array, at least under some circumstances. (For example, in Pascal, it has to be a value parameter, not a var parameter, and in C, the array has to be inside a struct.) These are not exactly obscure languages, so it's surprising that you assert there are no languages that work that way. Do you know any languages other than Java? “Every real language has types,” you say. Except for BLISS, BCPL, almost any assembly language, Forth, B, the Bourne shell, dc, QED, TECO, sed, and old versions of Tcl, to name a few. Again, these are not obscure languages; every piece of software you use is inspired by some of them and implemented in part in others. (There are also languages like Python in which there are only dynamic types, but I agree with your point of view that those are still types.) And that's why I downmodded your comment: not because it was arrogant, but because it was wrong.
- deleted 18y ago[deleted]