Java Philosophy

  • Thread starter Wildemar Wildenburger
  • Start date
W

Wildemar Wildenburger

Hi Folks,

I have now played with java for a while and I can't get very comfortable
with it. I don't really /dis/like, but it just hasn't "clicked" yet.

Maybe that is because I come from the Python world, which is (almost)
completely different in approach. Specifically I find Java to be overly
paranoid sometimes (what with interfaces, typing declarations, etc ...).
I see their value for optimization, but they hurt my brain because I'm
just used to the freedom. I'm not writing this as a flame; maybe some
Python-folks here can understand me.

What I'd like now is some sort of "Java Philosophy" text. Something like
a "spiritual guide" to Java, that would convey the right mindset for it.
A quick googling found me nothing that seemed consentient, most was
rather personal views. I've read the Java-is-not-Python thing, but that
didn't cut it (felt lame).

Any ideas? I'd love to hear them.
thx
/W
 
S

Stefan Ram

Wildemar Wildenburger said:
completely different in approach. Specifically I find Java to be overly
paranoid sometimes (what with interfaces, typing declarations, etc ...).
I see their value for optimization,

You see interfaces and typing declarations
having a value for optimization?

Then, maybe you can explain:

What do they optimize?

How do they do this?
What I'd like now is some sort of "Java Philosophy" text. Something like
a "spiritual guide" to Java, that would convey the right mindset for it.

To get the mindset, use Java.

See also

http://norvig.com/21-days.html
 
W

Wildemar Wildenburger

Stefan said:
You see interfaces and typing declarations
having a value for optimization?
Yes. Granted, I didn't give it that much thought.

Then, maybe you can explain:

What do they optimize?

How do they do this?
No. I'm not experienced enough to do so, and from the mere fact that you
ask this, I reckon that I was wrong in assuming they have
optimization-value. I was thinking something along the lines of memory
allocation or so.

You know, the friendly and much more useful way to point this out would
have been to just explain how my assumptions were wrong.

To get the mindset, use Java.
Oh thanks. I hadn't thought of that.

You know how many Python programs I've seen that were essentially Perl-,
Basic- or (very often) Java- programms trying to break free? I was
hoping (and still do) that there is some form of common "idealism"
regarding how to write Java code.

Cute.

I'm not in a rush, however. I just like to fly above as well as dive in.


/W
 
B

Bent C Dalager

Maybe that is because I come from the Python world, which is (almost)
completely different in approach. Specifically I find Java to be overly
paranoid sometimes (what with interfaces, typing declarations, etc ...).
I see their value for optimization, but they hurt my brain because I'm
just used to the freedom. I'm not writing this as a flame; maybe some
Python-folks here can understand me.

This is a very common feeling when you transition from a weakly typed
language to a more strongly typed one. I expect that the only way to
overcome it is to understand and embrace the advantages that stronger
typing gives you.
What I'd like now is some sort of "Java Philosophy" text. Something like
a "spiritual guide" to Java, that would convey the right mindset for it.
A quick googling found me nothing that seemed consentient, most was
rather personal views. I've read the Java-is-not-Python thing, but that
didn't cut it (felt lame).

In a nutshell (and probably with some important inaccuracies), this is
the philosophy that Java wants you to embrace:

- The compiler should be given the maximum possible capability to help
you detect errors in your code so that you may find and fix them prior
to deployment.

While I haven't coded any Python, I did code some ECMAScript a while
back and it occurred to me that the only way in which I could get my
ECMAScript code to be anywhere near my Java code in terms of
robustness was by significantly increasing the scope of my unit test
suite so as to cover variable types etc. And I'm not sure that this
would ever be able to get me the same robustness as Java does by
default.

Of course, there may be lint-like tools available for these languages
that are able to help you out further - I haven't looked into this.

Cheers,
Bent D
 
S

Stefan Ram

Wildemar Wildenburger said:
You know, the friendly and much more useful way to point this out
would have been to just explain how my assumptions were wrong.

An interface in Java is a means to write documentation (via
JavaDoc) for a verb once, so that the documentation can be
shared by several classes implementing this verb. For example,
the verb »compareTo« is being documented in

http://download.java.net/jdk7/docs/api/java/lang/Comparable.html#compareTo(T)

The documentation is refered in the following two classes,
each of which contains an implementation of this verb.

http://download.java.net/jdk7/docs/api/java/lang/Integer.html
http://download.java.net/jdk7/docs/api/java/lang/String.html

The documentation does not have to be given twice in each of
these classes. Instead both can refer the single documention
in the interface.

The verb »compareTo« has the same meaning in both classes, but
it might have different implementations. Only its meaning (its
interface and behavior) is relevant for clients, so it is all
a client programmer needs to know.

(Interfaces also are used for other purposes. Documentation
sharing is only one of them.)

What means does Python use to share documentation that is
the same for a verb appearing in two classes between those
two classes, so that there do not have to be two copies
of the documentation in each class?
 
J

John W. Kennedy

Wildemar said:
Yes. Granted, I didn't give it that much thought.


No. I'm not experienced enough to do so, and from the mere fact that you
ask this, I reckon that I was wrong in assuming they have
optimization-value.

Type declarations normally permit faster execution, compared to
languages like Python, Ruby, Perl, etc., by an order of magnitude or so,
because actual machines use typed data only, and have to go far out of
their way to fake typeless variables. This is not normally called
"optimization" because, traditionally, it is regarded as mere baseline
performance that "optimization" should proceed to improve upon.

Interfaces have more to do with catching logic errors at compile time
(instead of at run time) than they do with speed.
--
John W. Kennedy
"Give up vows and dogmas, and fixed things, and you may grow like That.
....you may come to think a blow bad, because it hurts, and not because
it humiliates. You may come to think murder wrong, because it is
violent, and not because it is unjust."
-- G. K. Chesterton. "The Ball and the Cross"
 
L

Lew

John said:
Type declarations normally permit faster execution, compared to
languages like Python, Ruby, Perl, etc., by an order of magnitude or so,
because actual machines use typed data only, and have to go far out of
their way to fake typeless variables. This is not normally called
"optimization" because, traditionally, it is regarded as mere baseline
performance that "optimization" should proceed to improve upon.

Interfaces have more to do with catching logic errors at compile time
(instead of at run time) than they do with speed.

And this leads us right into the philosophy of Java.

Java is a strongly-typed, object-oriented, network-aware, inherently
concurrent dynamic language.
 
W

Wildemar Wildenburger

Stefan said:
[snip useful explanation]

What means does Python use to share documentation that is
the same for a verb appearing in two classes between those
two classes, so that there do not have to be two copies
of the documentation in each class?
None, really, apart from inheriting docstrings from superclasses (Python
does multiple inheritance). Duck-typing usually alleviates the need for
different implementations of the "same" method.

But lets not get into any Python-vs-Java discussions please.

/W
 
P

Pritam Barhate

Hi Wildemar,

You wrote,
I have now played with java for a while and I can't get very comfortable
with it. I don't really /dis/like, but it just hasn't "clicked" yet.

Maybe that is because I come from the Python world, which is (almost)
completely different in approach.

Well the problem is that you come from Python Background. Had you come
from C++ background, like me, you would have loved the simplicity,
elegance and productivity of Java.

But still if you need convincing about Java being strongly typed then
here is the argument:

Being strongly typed insures that you are using right values for right
variables. A lot of mistakes are caught at compile time which saves a
lot of headache while testing the program.

This was the reason type-safe collections were introduced with JDK
1.5.

I appreciated Java's being strongly typed while coding JavaScript. And
for me the single most advantage of AJAX frameworks like GWT is that
they let me code in Java instead of JavaScript.

As far as interfaces are concerned I like them since I still remember
the horrible time I spent reading the chapters on multiple inheritance
in C++. It's a bit too confusing rather tan being help. What
interfaces do is that they remove the complexity of the multiple
inheritance yet allow us to develop useful polymorphic programs. If
you want to see how effectively interface-based polymorphism can be
put to use see how Database Access Objects (DAO) are created while
using frameworks like Spring. That was the first time I really
appreciated interfaces which allowed me to switch between JDBC based
DAOs to Hibernate based DAOs by just changing a XML file. (Of course I
had to write Hibernate DAOs but the coupling was changed with only
XML, no change to other business logic code.)

As far as a book explaining "Java Philosophy" is concerned I don't
know if any such book exists. But from whatever I have read if
anything can come closer to become "The Standard way of Coding in
Java" then it is "Effective Java Programming Language Guide" by Joshua
Bloch.

Another book you may want to take a look at is "Thinking in Java" by
Bruce Eckel. the book is available for free for online reading.
 
L

Lew

Pritam said:
As far as a book explaining "Java Philosophy" is concerned I don't
know if any such book exists. But from whatever I have read if
anything can come closer to become "The Standard way of Coding in
Java" then it is "Effective Java Programming Language Guide" by Joshua
Bloch.

Another book you may want to take a look at is "Thinking in Java" by
Bruce Eckel. the book is available for free for online reading.

That second recommendation is a tad controversial. Mr. Eckel's way of
"Thinking in Java" isn't quite consonant with the likes of Bloch, Goetz or
Lea. It's good, but be prepared to do a mindshift after, to accomodate the
more Java-esque way of thinking in Java.
 
R

RedGrittyBrick

Lew said:
That second recommendation is a tad controversial. Mr. Eckel's way of
"Thinking in Java" isn't quite consonant with the likes of Bloch, Goetz
or Lea. It's good, but be prepared to do a mindshift after, to
accomodate the more Java-esque way of thinking in Java.

I note that the second edition of Block's book covers Java SE 6. Not yet
available from Amazon but RSN?
 
J

Joe Attardi

Daniel said:
Amazon UK lists a release date of 28th June 2008.

Bummer. I just bought the older version at Barnes & Noble last week! I
guess it will still be a good read, though. Not everything is specific
to the platform version, I guess.
 
W

Wildemar Wildenburger

Bent said:
In a nutshell (and probably with some important inaccuracies), this is
the philosophy that Java wants you to embrace:

- The compiler should be given the maximum possible capability to help
you detect errors in your code so that you may find and fix them prior
to deployment.
OK. That particular point is addressed in the tutorial as well. Now that
you point it again, I will maybe perhaps start considering giving it
some thought. :)

While I haven't coded any Python, I did code some ECMAScript a while
back and it occurred to me that the only way in which I could get my
ECMAScript code to be anywhere near my Java code in terms of
robustness was by significantly increasing the scope of my unit test
suite so as to cover variable types etc. And I'm not sure that this
would ever be able to get me the same robustness as Java does by
default.
Maybe this is (one of) the crucial point(s): Java was created with "the
industry" in mind, doing big projects, grand "deployment" and all. That
would serve well to justify the rigor of it; it catches certain errors
before anybody else sees your code.

/W
 
W

Wildemar Wildenburger

Pritam said:
Well the problem is that you come from Python Background.
Well, I wouldn't call it a *problem* ... ;)

As far as a book explaining "Java Philosophy" is concerned I don't
know if any such book exists. But from whatever I have read if
anything can come closer to become "The Standard way of Coding in
Java" then it is "Effective Java Programming Language Guide" by Joshua
Bloch.
Looks interesting, I'll have a look. Thanks (also for the rest of your
post, very interesting). :)

/W
 
R

Roedy Green

What I'd like now is some sort of "Java Philosophy" text. Something like
a "spiritual guide" to Java, that would convey the right mindset for it.
A quick googling found me nothing that seemed consentient, most was
rather personal views. I've read the Java-is-not-Python thing, but that
didn't cut it (felt lame).

I hate relaxed type languages. Yes strict typing takes more type to
type, but it saves time in the long run. It is much easier to
understand what the code is doing when you have the types clearly laid
out. Compile time checking excludes many errors.

It comes down to what you are doing. If you are whipping out little
one shot programs that you run once, then discard, and you are a slow
typist, then relaxed typing is the way to fly.

If you write systems that you keep coming back to for maintenance over
the years, approaching each time cold, largely forgetting how the
program works, with only your notes and the code to get up to speed,
then you appreciate the tight typing.

Learning to type quickly, using a high quality keyboard such as the
kinesis or Maltron, and an optimised layout such as DSK, can take much
of the pain out of the verbosity. A smart IDE helps too.
see http://mindprod.com/bgloss/keyboard.html
 
A

Alexey

I have been coding in Java since its early days. Throughout this time
and before, I used other languages, such as Turbo Pascal, Perl,
Javascript, and most recently C#. Java is a multifaceted beast. Here
are some of the attributes I find important:

* type safety of the language and runtime environment
* garbage collection
* easy multithreading
* easy networking
* extensive standard libraries as well as EE and 3rd party options
* runtime optimization
* cross-platform (let's not forget J2ME and Android for embedded VM's)
* backwards compatible source, standard API (excepting a very slow
deprecation process), and compiled form
* alternate languages running on JVM (Scala, JRuby, Jython, BeanShell,
Rhyno/ECMAScript, etc.)
* Java source compiled to non-JVM environments (GWT, Android)

There's more, but that's good enough for now. Don't fear the apparent
complexity of API, frameworks or deployment. We're up to Java 6 and I
doubt there's anyone on this planet who has comprehensive
understanding of everything in the Java world. Some things overlap
each other, some solutions compete with each other, some have not
caught up to the latest language features that allow them to become
simpler (take a look at JEE 5 and how annotations are actually
simplifying things like web services).
 

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,780
Messages
2,569,610
Members
45,254
Latest member
Top Crypto TwitterChannel

Latest Threads

Top