Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Page 2 of 2 FirstFirst 12
Results 26 to 32 of 32

Thread: Can't pass by reference?

  1. #26
    Junior Member
    Join Date
    Aug 2014
    Posts
    14
    My Mood
    Bored
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Can't pass by reference?

    I completely agree, this is an appealing thing about java, it is very safe, this is a pro about java.... very safe. For very high performance ... not so good. Have a dabble with DirectX and you'll see. Again... Java is great for certain things and I agree with you, it is much safer than C++, harder for catastrophies to happen.

  2. #27
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Can't pass by reference?

    Quote Originally Posted by JavaDeveloperPeter View Post
    I'm just surprised at how high handed people are, talking like that
    Quote Originally Posted by JavaDeveloperPeter View Post
    do you even appreciate why passing by reference is useful, do you know why people use newton solvers, do you even know what one is? I can suggest using a tutor if you would like to find out
    Sigh. Do you not see your hypocrisy?

    Are you implying that you *can't* do this with Java? That it *must* use pass-by-reference?

    Again, this is a technical forum. This thread will be closed if the personal attacks and off-topic whining continue. Continued trolling will result in a ban.

    You can either feign offense again, or move on and get back to the technical aspects of what you're confused by. It's up to you how to proceed from here.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #28
    Member jdv's Avatar
    Join Date
    Jul 2014
    Location
    This Land
    Posts
    73
    Thanks
    0
    Thanked 5 Times in 5 Posts

    Default Re: Can't pass by reference?

    As a meta-comment I'll suggest this is why, for me, it is so important to study multiple languages, and (like the OP) challenge received wisdom about language internals. Even this many years on, I still find interesting corners in C++, Java, etc.

    The key is that these languages are, by and large, living languages used as tools to get Real Work done. So design trade-offs are made and dangerous corners abide.

    This is true for any sufficiently complex toolset.

  4. #29
    Junior Member
    Join Date
    Aug 2014
    Posts
    14
    My Mood
    Bored
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Can't pass by reference?

    Kevin, Haha "that you are confused by", no just disappointed, but you have to make a personal attack and say I'm confused... Mr Hypocrit. I'm not confused I understand what Java can and cannot do. And I did implement a newton solver in Java... of course it can be done. I just say that it's slicker and more boiled down to the nuts and bolts with C++. And it takes two to tango, this is just an interesting conversation..

    --- Update ---

    Completely agree with you jdv. Cheers.
    Last edited by JavaDeveloperPeter; August 25th, 2014 at 12:16 PM.

  5. #30
    Member Ada Lovelace's Avatar
    Join Date
    May 2014
    Location
    South England UK
    Posts
    414
    My Mood
    Angelic
    Thanks
    27
    Thanked 61 Times in 55 Posts

    Default Re: Can't pass by reference?

    Pointers (in my view) are something I am glad to not have to worry about anymore.
    I spent five years dealing with them, malloc() and free() where two functions in C
    that I waved good-bye too. Yes I did see their uses and most of the time when used
    correctly they did work and did a good job.

    References work "almost" identical to pointers (you cannot allocate memory through a
    reference). In languages like C and C++ references where used to pass a value to a
    function (called "call-by-reference"), but it would only pass the address of the value
    not the value itself. The said method could then alter the value, and any changes made
    to that value would also effect the original value in the calling function.

    I personally prefer Java's way of doing things, I find it safer to pass by value. It means
    the original value cannot be accidently altered by another method, and that always
    creates cleaner code to look at

    Just my two cents.

    Wishes Ada xx
    If to Err is human - then programmers are most human of us all.
    "The Analytical Engine offers a new, a vast, and a powerful language . . .
    for the purposes of mankind
    ."
    Augusta Ada Byron, Lady Lovelace (1851)

  6. #31
    Member jdv's Avatar
    Join Date
    Jul 2014
    Location
    This Land
    Posts
    73
    Thanks
    0
    Thanked 5 Times in 5 Posts

    Default Re: Can't pass by reference?

    Finally (I promise!) I think this is why it is so important to evaluate language features and choices critically and fairly. How /useful/ is pass-by-reference in an essentially user-pointer-free language? How often are we going to need this, once we wrap our heads around idiomatic Java?

    This is the problem I have when learning a new language. It is very useful to use another language as a reference as sort of leverage to bootstrap oneself. But this can easily get in the way when I start writing actual code. A mentor, lo, those many years ago once told me in a code review: "When in C, think like a C code; when in Java, think like a Java coder". This applies to things like formatting and whitespace just as much as it applies to idioms.

    Yet, learning to Think Like A ... Coder is arguably the most challenging aspect of learning a new language beyond apprenticeship level and well into journeyman and (hopefully) beyond.

    Heck, even going from Java 6 to Java 7 has opportunity for reevaluating those well-worn idioms. And remember even earlier when we didn't have for-each loops and had to always use an iterator?

    This is a real issue in the industry, as those of us who have seen so much "C-with-objects" C++ code to maintain over the years can attest to!

    At the end of the day, if you are doing this for more than just fun, employers are paying for you to solve problems and ship product, not complain that Your Language Sucks. The YLS approach can be in good fun sometimes, but it isn't solving problems and shipping product.

    In closing, I'll paraphrase what a friend of mine said recently regarding Java and C#. This person was, for years, on the C# compiler team at MSFT, and literally wrote the book on the language.

    "We didn't want to directly compare the languages for any reason, as they exist in different domains, but it was hard not to describe C# as Java with all the bad bits taken out."

    My recent express review of C# actually reinforces this sentiment!
    Last edited by jdv; August 25th, 2014 at 12:35 PM. Reason: Clarify clarify clarify

  7. #32
    Junior Member
    Join Date
    Aug 2014
    Posts
    14
    My Mood
    Bored
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Can't pass by reference?

    Hi Ada, I agree with you and as I'm starting to use java having used unmanaged c++ and c, I also will not miss free() and malloc(). I agree with your point on the safety of it too, and for the right job, which surely is very many, Java is very good. It seems to me that one of the important points that java is based off is to stop these irritating little bugs appearing, which I start to appreciate more and more. An example that just sprung to mind is the @Override in java... very nice - I've seen nasty bugs appearing at work when someone changes a virtual method to const or not being const and then no inherited methods kick in... another nice belt and braces thing in Java.
    Cheers,
    Peter

    --- Update ---

    Quote Originally Posted by jdv View Post
    "We didn't want to directly compare the languages for any reason, as they exist in different domains, but it was hard not to describe C# as Java with all the bad bits taken out."

    My recent express review of C# actually reinforces this sentiment!
    :-)

Page 2 of 2 FirstFirst 12

Similar Threads

  1. not sure how to pass this value
    By iamgonge in forum What's Wrong With My Code?
    Replies: 3
    Last Post: May 16th, 2013, 01:08 AM
  2. Get Reference of js files
    By Priyankati in forum Other Programming Languages
    Replies: 1
    Last Post: February 11th, 2013, 12:04 PM
  3. Value vs Reference Types
    By anis.laghaei in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 23rd, 2012, 01:21 PM
  4. [SOLVED] Pass-by-Value scheme, puzzled with passing/assigning a reference to another object
    By chronoz13 in forum Java Theory & Questions
    Replies: 10
    Last Post: June 2nd, 2012, 10:43 AM
  5. 'pass by value' and 'pass by reference'
    By pokuri in forum Object Oriented Programming
    Replies: 5
    Last Post: January 26th, 2011, 11:30 AM