Immutable Datastructures with good Sharing

C

Cthun

Perhaps looking into the standard libraries of Scala or Clojure would be
a good idea. Both provide immutable lists, trees, vectors, hashmaps etc.

Clojure's can be used from in Java by importing clojure.lang classes and
having the Clojure jar in the classpath. No generics, but they implement
the unmodifiable-foo portions of the Map, Set, List, etc. interfaces
from java.util and have their own return-a-modified-version methods.
There's a persistent immutable stack class included.

I'm not sure if clojure.lang has a persistent immutable queue, or if it
does if it's a deque, but someone posted code for a queue on their
mailing list a year or so ago. I'm not sure who or exactly when, but a
search for "persistent queue" will probably turn it up. I think it was a
full deque with pushes, peeks, and pops at both ends stated to be O(1).
It used deftype/defprotocol which, if I understand them correctly,
generates named Java classes and interfaces that can be imported into
and used from Java if the Clojure code is AOT-compiled to generate
..class files. I don't know what, if any, license the author specified
though.

I also recall seeing a priority queue implementation posted there at
some point.

Of course, you might want to take the larger step of actually using
Clojure if persistence and immutability are things you crave. ;)
 
A

Arne Vajhøj

Am I stuck to 1.6? static methods with generics in Java 1.6 is a "trick" and
obsolete in 1.7?

Unless that static factory does more than just new, then I
would consider it "old style" with "new style" being
the 1.7 diamond operator.

What exactly the difference if any between "old style" and
"obsolete" is somewhat subjective.

Arne
 
T

Tom Anderson

When you say it like this, any function can be labeled as "unhelpful
obfuscation" :)

Touché! I would agree that any function is obfuscation; whether it is
helpful or unhelpful obfuscation varies.

tom
 
T

Tom Anderson

Side note: One might observe that this 'E' does not correspond to the
'E' of the outer class's generic parameter. One might also observe that
this does no harm whatsoever.

Yes, certainly worth noting, though. I did have this being a non-static
inner class at some point; i think that works, but given that instances of
it are shared between many different instances of the outer class, it
seems wrong.
Side note 2: TABs? Really?

I wrote it in Eclipse, which i have set up to use tabs, and
copy-and-pasted it. The tabs stayed tabs. I could have reformatted it with
spaces, but i just wanted to post it and get to bed.

Actually, i did it just to annoy you.
Alternative form if you like for loops:

for (Link<E> link = head; link != tail; link = link.next) {
++size;
}

Yes, that's nice.

A serious implementation of this would probably just track the size in a
variable, rather than counting the links each time.

tom
 
S

Stefan Ram

Tom Anderson said:
Touché! I would agree that any function is obfuscation; whether it is
helpful or unhelpful obfuscation varies.

A well-known function name is not obfuscation, for example,

y = sin x,

compared to

y = uht x

. To a Java-Programmer,

new ArrayList<RequestData>()

is well-known, while

Lists.newArrayList()

is less-known or unknown. For a Guava-Programmer it might be
the other way round.

However, in Java,

new ArrayList<RequestData>()

is an instance-creation expression, not a function. A Java
programmer cannot know what

Lists.newArrayList()

is in Guava, especially he cannot know whether this is a
function, a function call or whatever in Guava. In Java,
it would be a function call when used as an expression.

To a speaker of Chinese (who does not know English),
English is obfuscation.

During my years on the Usenet, I am slowly learning to
read ROT13 texts directly as they are written.
 
S

Stefan Ram

Supersedes: <[email protected]>

Tom Anderson said:
Touché! I would agree that any function is obfuscation; whether it is
helpful or unhelpful obfuscation varies.

A well-known function name is not obfuscation, for example,

y = sin x,

compared to

y = uht x

. To a Java-Programmer,

new ArrayList<RequestData>()

is well-known, while

Lists.newArrayList()

is less-known or unknown. For a Guava-Programmer it might be
the other way round.

However, in Java,

new ArrayList<RequestData>()

is an instance-creation expression, not a function. A Java
programmer cannot know what

Lists.newArrayList()

is in Guava, especially he cannot know whether this is a
function, a function call or whatever in Guava.

[PS: If Guava is not a different language, but only a
Java library, the preceding sentence does not apply.]

In Java, it would be a function call when used as an
expression.

To a speaker of Chinese (who does not know English),
English is obfuscation.

During my years on the Usenet, I am slowly learning to
read ROT13 texts directly as they are written.
 
B

B1ll Gat3s

Yes - it's very clear.
No - it's not.
No - it's not.

Hey, coward, mind posting using your own name or whatever handle you're
usually known as instead of using mine?
 
B

B1ll Gat3s

From a idiot.extreme-one came the gem:
Hey, coward, mind posting using your own name or whatever handle you're
usually known as instead of using mine?

--------------forgery alert... play nice, leave off with the multiple name use in CLJP
Report sent - X-Complaints-To: (e-mail address removed)
 
C

Cthun

Yes - identify the lines, genius.

?

Download it yourself or browse the source file at github if for some
reason you want to know what line numbers of what file contain the stack
class.
Yes - it's very clear.
??

No - it's not.
???

No - it's not.

????

Are you on crack?
 
T

thoolen

On 07/11/2011 6:07 PM, murphy wrote:
NaN> Newsgroups: comp.lang.java.programmer

NaN> Yes - identify the lines, genius.

What does your directive to Cthun have to do with Java, murphy?

NaN> Yes - it's very clear.

Classic ambiguity.

NaN> No - it's not.

Non sequitur.

NaN> No - it's not.

Non sequitur.

"I had 'volunteered (years back) to support those who do endeavor
to provide free Free Usenet access, support those who offered
subscription based Free Usenet access, nothing more than
cooperation expected in return for what has been many
thousands of hours of work. I note most of those I joined with
are either deceased, severely disabled, or plain ole' MIA..
now it is my Time. ...

You just read my last. ...

For those who think they see me in future times I can only wish
you severe Tinnitus in your dreams. For those who know me
well (eMail, whatever) and see me, know I will be smiling also.
It is to you I say "adieu mein frenz and adios .. grazie' [hugs]
for all the Good Times! May you and yours always bear well
with all Life brings you".

/0ut"
--murphy

http://www.uffnet.com/kookkamp/goodbye.htm

And some people wonder why I call them Famous Last Words.

P.S. You forgot to include a copy of your trademarked Lits o' Haet,
murphy. Still suffering from memory problems, murphy?
 
T

thoolen

On 08/11/2011 12:17 AM, murphy wrote:
NaN> From a idiot.extreme-one came the gem:

Who is "a idiot.extreme-one", murphy? There is nobody in this newsgroup
using that alias.

NaN> --------------forgery alert...

What does your forgery have to do with Java, murphy? Forgeries are more
effective if you don't alert everyone to the fact of your forgery, murphy.

NaN> play nice, leave off with the multiple name use in CLJP

What does your ironic directive to B1ll Gat3s have to do with Java, murphy?

NaN> Report sent - X-Complaints-To: (e-mail address removed)

How ironic.

"I had 'volunteered (years back) to support those who do endeavor
to provide free Free Usenet access, support those who offered
subscription based Free Usenet access, nothing more than
cooperation expected in return for what has been many
thousands of hours of work. I note most of those I joined with
are either deceased, severely disabled, or plain ole' MIA..
now it is my Time. ...

You just read my last. ...

For those who think they see me in future times I can only wish
you severe Tinnitus in your dreams. For those who know me
well (eMail, whatever) and see me, know I will be smiling also.
It is to you I say "adieu mein frenz and adios .. grazie' [hugs]
for all the Good Times! May you and yours always bear well
with all Life brings you".

/0ut"
--murphy

http://www.uffnet.com/kookkamp/goodbye.htm

And some people wonder why I call them Famous Last Words.

P.S. You forgot to include a copy of your trademarked Lits o' Haet,
murphy. Still suffering from memory problems, murphy?
 
B

B1ll Gat3s

From Cthun said:
Download it yourself or browse the source file at github if for some
reason you want to know what line numbers of what file contain the stack
class.
classic fooktard presupposition
is Derbyshireite for ?
is Derbyshireite for ?
is Derbyshireite for ?
Are you on crack?
your obsession with owning the crackpot th00len
identity is related to Java how, Paul?

How cute to see you two fooktards...tied at the
ankle...bouncing into CJLP in perfect unison.
Murphy would be most amused.
Onto a technical issue, why is (e-mail address removed)
not being recognized?
 
T

thoolen

On 08/11/2011 6:01 PM, murphy wrote:
NaN> Newsgroups: comp.lang.java.programmer

NaN> From Cthun <[email protected]> classic idiot.extreme-one came the
NaN> gem:

What does your unsubstantiated allegation regarding Cthun's IQ have to
do with Java, murphy?

NaN> classic fooktard presupposition

What does your fooktard presupposition have to do with Java, murphy?

NaN> is Derbyshireite for ?

What it "Derbyshireite", murphy, and what does it have to do with Java?

NaN> is Derbyshireite for ?

What it "Derbyshireite", murphy, and what does it have to do with Java?

NaN> is Derbyshireite for ?

What it "Derbyshireite", murphy, and what does it have to do with Java?

NaN> your obsession with owning the crackpot th00len
NaN> identity is related to Java how, Paul?

Who is "Paul", murphy? There is nobody in this newsgroup using that alias.

NaN> How cute to see you two fooktards...tied at the ankle...bouncing into
NaN> CJLP in perfect unison.

What does your classic erroneous presupposition have to do with Java,
murphy?

NaN> Murphy would be most amused.

What does your amusement have to do with Java, murphy?

NaN> Onto a technical issue, why is (e-mail address removed)
NaN> not being recognized?

What does your ambiguous question of Cthun have to do with Java, murphy?

"I had 'volunteered (years back) to support those who do endeavor
to provide free Free Usenet access, support those who offered
subscription based Free Usenet access, nothing more than
cooperation expected in return for what has been many
thousands of hours of work. I note most of those I joined with
are either deceased, severely disabled, or plain ole' MIA..
now it is my Time. ...

You just read my last. ...

For those who think they see me in future times I can only wish
you severe Tinnitus in your dreams. For those who know me
well (eMail, whatever) and see me, know I will be smiling also.
It is to you I say "adieu mein frenz and adios .. grazie' [hugs]
for all the Good Times! May you and yours always bear well
with all Life brings you".

/0ut"
--murphy

http://www.uffnet.com/kookkamp/goodbye.htm

And some people wonder why I call them Famous Last Words.

P.S. You forgot to include a copy of your trademarked Lits o' Haet,
murphy. Still suffering from memory problems, murphy?
 
C

Cthun

On 08/11/2011 6:01 PM, murphy wrote:
NaN> Newsgroups: comp.lang.java.programmer
NaN> From Cthun <[email protected]> classic idiot.extreme-one came the
NaN> gem:

What does your unsubstantiated allegation regarding Cthun's IQ have to
do with Java, murphy?
No, no, a thousand times no! None of the nasty things that you have
said or implied about me are at all true.

Are you on crack?

(noop)NaN>classic fooktard presupposition
(noop)
(noop)What does your fooktard presupposition have to do with Java, murphy?
(noop)
(noop)NaN>is Derbyshireite for ?
(noop)
(noop)What it "Derbyshireite", murphy, and what does it have to do with Java?
(noop)
(noop)NaN>is Derbyshireite for ?
(noop)
(noop)What it "Derbyshireite", murphy, and what does it have to do with Java?
(noop)
(noop)NaN>is Derbyshireite for ?
(noop)
(noop)What it "Derbyshireite", murphy, and what does it have to do with Java?
(noop)
(noop)NaN>your obsession with owning the crackpot th00len
(noop)NaN>identity is related to Java how, Paul?
(noop)
(noop)Who is "Paul", murphy? There is nobody in this newsgroup using that alias.
(noop)
(noop)NaN>How cute to see you two fooktards...tied at the ankle...bouncing into
(noop)NaN>CJLP in perfect unison.
(noop)
(noop)What does your classic erroneous presupposition have to do with Java,
(noop)murphy?
(noop)
(noop)NaN>Murphy would be most amused.
(noop)
(noop)What does your amusement have to do with Java, murphy?
(noop)
(noop)NaN>Onto a technical issue, why is (e-mail address removed)
(noop)NaN>not being recognized?
(noop)
(noop)What does your ambiguous question of Cthun have to do with Java, murphy?
(noop)
(noop) "I had 'volunteered (years back) to support those who do endeavor
(noop) to provide free Free Usenet access, support those who offered
(noop) subscription based Free Usenet access, nothing more than
(noop) cooperation expected in return for what has been many
(noop) thousands of hours of work. I note most of those I joined with
(noop) are either deceased, severely disabled, or plain ole' MIA..
(noop) now it is my Time. ...
(noop)
(noop) You just read my last. ...
(noop)
(noop) For those who think they see me in future times I can only wish
(noop) you severe Tinnitus in your dreams. For those who know me
(noop) well (eMail, whatever) and see me, know I will be smiling also.
(noop) It is to you I say "adieu mein frenz and adios .. grazie' [hugs]
(noop) for all the Good Times! May you and yours always bear well
(noop) with all Life brings you".
(noop)
(noop) /0ut"
(noop) --murphy
(noop)
(noop)http://www.uffnet.com/kookkamp/goodbye.htm
(noop)
(noop)And some people wonder why I call them Famous Last Words.
(noop)
(noop)P.S. You forgot to include a copy of your trademarked Lits o' Haet,
(noop)murphy. Still suffering from memory problems, murphy?
 
T

thoolen

On 08/11/2011 10:43 PM, murphy wrote:
NaN> Newsgroups: comp.lang.java.programmer

NaN> No, no, a thousand times no!

What does your denial have to do with Java, murphy?

NaN> None of the nasty things that you have said or implied about me
NaN> are at all true.

What does your classic erroneous presupposition have to do with Java,
murphy?

NaN> Are you on crack?

What does your ridiculous question have to do with Java, murphy?

"I had 'volunteered (years back) to support those who do endeavor
to provide free Free Usenet access, support those who offered
subscription based Free Usenet access, nothing more than
cooperation expected in return for what has been many
thousands of hours of work. I note most of those I joined with
are either deceased, severely disabled, or plain ole' MIA..
now it is my Time. ...

You just read my last. ...

For those who think they see me in future times I can only wish
you severe Tinnitus in your dreams. For those who know me
well (eMail, whatever) and see me, know I will be smiling also.
It is to you I say "adieu mein frenz and adios .. grazie' [hugs]
for all the Good Times! May you and yours always bear well
with all Life brings you".

/0ut"
--murphy

http://www.uffnet.com/kookkamp/goodbye.htm

And some people wonder why I call them Famous Last Words.

P.S. You forgot to include a copy of your trademarked Lits o' Haet,
murphy. Still suffering from memory problems, murphy?
 
T

Tom Anderson

Supersedes: <[email protected]>



A well-known function name is not obfuscation, for example,

y = sin x,

compared to

y = uht x

It *is* obfuscation, because you can't look at that statement and
immediately see what it does. You rely on your general knowledge of the
sine function - and of what angle unit this particular implementation
happens to be using, what it does for out-of-range values, and so on. I
would readily agree that calling it uht would make it even more mysterious
to an oligolingual programmer such as myself, but the fact is that hiding
the implementation behind any name is obfuscation.

The point is that obfuscation is not necessarily a bad thing! It's just
that when we think it's a good thing, we tend to call it 'encapsulation'.

tom
 
G

Gene Wirchenko

[snip]
The point is that obfuscation is not necessarily a bad thing! It's just
that when we think it's a good thing, we tend to call it 'encapsulation'.

The two are not the same. Making something more difficult to
understand is not the same as hiding it.

Sincerely,

Gene Wirchenko
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,123
Latest member
Layne6498
Top