Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Java (http://www.velocityreviews.com/forums/f30-java.html)
-   -   Null pointer issues (http://www.velocityreviews.com/forums/t721354-null-pointer-issues.html)

Jack 04-24-2010 05:26 PM

Null pointer issues
 
Java avoids the memory access violation suffered by C/C++. But it
still has the null pointer issue. Certainly, this makes Java code
safer than C/C++ code. But you can control memory directly with C/C++.
Is there any other advantages of Java on this perspective?

Thanks.

Jack

Arne Vajhj 04-24-2010 06:10 PM

Re: Null pointer issues
 
On 24-04-2010 13:26, Jack wrote:
> Java avoids the memory access violation suffered by C/C++. But it
> still has the null pointer issue. Certainly, this makes Java code
> safer than C/C++ code. But you can control memory directly with C/C++.
> Is there any other advantages of Java on this perspective?


Garbage collection !

Arne

markspace 04-24-2010 06:50 PM

Re: Null pointer issues
 
Jack wrote:

> Java avoids the memory access violation suffered by C/C++. But it
> still has the null pointer issue. Certainly, this makes Java code
> safer than C/C++ code. But you can control memory directly with C/C++.
> Is there any other advantages of Java on this perspective?



Also, the lack of direct memory control in Java means it's really hard
to mess up memory allocation.

I haven't played with C++ in a while, but there's certainly some darn
weird things you can do with memory allocation in that language. The
guys who program in C++ all the time seem to love it, but to me it just
looks like a opportunity to make some really serious errors and write a
bunch of byte where they shouldn't go.

In Java, your options are much more limited, but also much safer. You
can allocate memory with new (which cannot be overloaded like C++):

Object object = new SomeObject();

or you can allocate contiguous buffers with arrays:

byte[] buffer = new byte[256];

And fundamentally that's all I can think of. Both these objects are
subject to garbage collection, so there's no destructors to worry about,
all Java methods are virtual by default, and all objects are referred to
by reference, so copy constructors are not needed (or available, really).

All this makes it much easier to do "real" object oriented programming
in Java, imo, rather than have to worry about a lot of little low level
methods or deal with memory de-allocation on a class-by-class basis,
something I always found tedious and error-prone in C++.

Lew 04-24-2010 08:36 PM

Re: Null pointer issues
 
Jack wrote:
> Java avoids the memory access violation suffered by C/C++. But it
> still has the null pointer issue. Certainly, this makes Java code
> safer than C/C++ code. But you can control memory directly with C/C++.
> Is there any other advantages of Java on this perspective?


You don't have to control memory directly as you do in C/C++.

--
Lew

Joshua Cranmer 04-24-2010 10:51 PM

Re: Null pointer issues
 
On 04/24/2010 01:26 PM, Jack wrote:
> Java avoids the memory access violation suffered by C/C++. But it
> still has the null pointer issue. Certainly, this makes Java code
> safer than C/C++ code. But you can control memory directly with C/C++.
> Is there any other advantages of Java on this perspective?


Direct access to memory is a mixed blessing. You can do... "crazy" stuff
with it, but for most programs, it's not exactly something that one
needs to be able to do. The cost of this is that you have to manage
memory yourself--for large, complex problems, manual memory management
results in high costs, and you may end up implementing what the JVM has
already implemented for you.

--
Beware of bugs in the above code; I have only proved it correct, not
tried it. -- Donald E. Knuth

Roedy Green 04-25-2010 04:51 PM

Re: Null pointer issues
 
On Sat, 24 Apr 2010 10:26:56 -0700 (PDT), Jack <junw2000@gmail.com>
wrote, quoted or indirectly quoted someone who said :

>Java avoids the memory access violation suffered by C/C++. But it
>still has the null pointer issue. Certainly, this makes Java code
>safer than C/C++ code. But you can control memory directly with C/C++.
>Is there any other advantages of Java on this perspective?


It is impossible to write code that runs differently every time
because you forgot to initialise something. Java either initialises
for you or insists you do it.

In Java it is impossible to free an object yet retain pointers to it.

In Java it is impossible to leap into the middle of random code/data
and start executing doing all manner of weird things.

In Java it is impossible to have a pointer point to something other
than what it purports to.
--
Roedy Green Canadian Mind Products
http://mindprod.com

Its amazing how much structure natural languages have when you consider who speaks them and how they evolved.

Lew 04-25-2010 05:42 PM

OT: structure of natural language (Was: Null pointer issues)
 
Roedy Green wrote in his sig:
> It’s amazing how much structure natural languages have
> when you consider who speaks them and how they evolved.


Nonsense. When you see how much structure natural nature has overall
(remember physics, anyone? biology?) it makes sense that any given natural
process has structure.

Of course, I do agree that it is amazing that nature has such structure, and
even more amazing that we have some capability to apprehend it. But there's
no reason to suspect or expect natural language to be any less structured than
anything else in nature.

--
Lew

Roedy Green 04-27-2010 03:10 PM

Re: OT: structure of natural language (Was: Null pointer issues)
 
On Sun, 25 Apr 2010 13:42:45 -0400, Lew <noone@lewscanon.com> wrote,
quoted or indirectly quoted someone who said :

>> It’s amazing how much structure natural languages have
>> when you consider who speaks them and how they evolved.

>
>Nonsense. When you see how much structure natural nature has overall
>(remember physics, anyone? biology?) it makes sense that any given natural
>process has structure.


The thing I find odd is that people can speak sentences, who could not
for the life of them parse a sentence into nouns, verbs etc. I would
have expected human language to have evolved much simpler grammars.
Even the stupidest people can master a very complex grammar to speak
it. Why did so many languages for example assign arbitrary genders to
nouns -- a pointless complication?

This illustrates Stephen Pinker's contention that our language ability
is hard wired.

You can tell that people are using rules, not just memorising phrases,
by listening to small children who regularise the grammars, e.g. I
gived.

Notice the difference between computer languages and natural
languages.

Computer languages are essentially list of commands, and information
needed to execute the commands. Natural language is essentially a
description of external reality, particularly the actions of humans.

Computer languages are not big on pronouns.

Natural languages have a canonical pronunciation.

Computer languages are big on bracketting with () [] { }. Natural
languages don't do nesting well.

--
Roedy Green Canadian Mind Products
http://mindprod.com

Its amazing how much structure natural languages have when you consider who speaks them and how they evolved.

Lew 04-27-2010 07:11 PM

Re: OT: structure of natural language (Was: Null pointer issues)
 
Roedy Green wrote:
> The thing I find odd is that people can speak sentences, who could not
> for the life of them parse a sentence into nouns, verbs etc. I would


That is no more odd nor less wondrous than that a butterfly can
migrate to the same location thousands of miles away every year but
for the life of it cannot point out to you which way "north" is.

> have expected human language to have evolved much simpler grammars.
> Even the stupidest people can master a very complex grammar to speak


Even the smartest butterfly is stupider than that person.

> it. Why did so many languages for example assign arbitrary genders to
> nouns -- a pointless complication?
>


But ships really are female!

Certainly the universe is.

> This illustrates Stephen Pinker's contention that our language ability
> is hard wired. *
>


Just like the butterfly's navigation ability.

> You can tell that people are using rules, not just memorising phrases,
> by listening to small children who regularise the grammars, e.g. I
> gived.
>


--
Lew


All times are GMT. The time now is 02:25 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.