why is Java the way it is?

I

Ian Semmel

Roedy said:
Why not? I am not asking about the language as defined now, but what
the language designers might have been thinking when they concocted
the syntax.

They might have considered it and asked "Why on earth would anyone want to write something like that?"
 
A

Andreas Leitgeb

Roedy Green said:
Figuring out nesting and fixing broken nesting is
by far the syntax feature of Java what wastes the
most of my time and the one that I find hardest
just to eyeball.

What editor do you use? Most editors designed
for coding should have a feature "find matching
paranthese/brace/bracket/...".
In vi, it's "%". I've seen it in ultraedit as well
(but don't remember the keyboard shortcut) and
I'd be surprised, if eclipse and netbeans didn't
have such a feature.
I suggest some ways out in my Scid project. See
http://mindprod.com/project/scid.html

&%$/&%$&/Webwasher seems to have decided that your page
belongs to categories: (Politics, Extreme).
(Just for your information. I've got my ways
to still view it, though less convenient)
 
M

Mike Schilling

Andreas said:
What editor do you use? Most editors designed
for coding should have a feature "find matching
paranthese/brace/bracket/...".
In vi, it's "%". I've seen it in ultraedit as well
(but don't remember the keyboard shortcut) and
I'd be surprised, if eclipse and netbeans didn't
have such a feature.

IntelliJ, at least, has the ability to indent the code according to
the nesting level. This makes missing or superfluous braces obvious.
 
T

Tom Anderson

Or

for (int place = s.indexOf(x); place >= 0; place = s.indexOf(x))

Which isn't bad except for the redunancy in the first and third clauses.

Even worse! More characters duplicated, and a duplication where
differences between the two won't be caught by the compiler - with the
duplicated variable name, they probably will.

tom
 
T

Tom Anderson

Why not? I am not asking about the language as defined now, but what
the language designers might have been thinking when they concocted the
syntax.

I would guess it just never occurred to them. The model of statements and
expressions, with the former containing the latter but not vice versa, is
a very ancient one, that has generally served us pretty well.

tom
 
S

Stefan Ram

Tom Anderson said:
I would guess it just never occurred to them. The model of
statements and expressions, with the former containing the
latter but not vice versa, is a very ancient one, that has
generally served us pretty well.

In Java, an expression /can/ contain a statement.

In C, »( printf( "a" ), printf( "b" ))« is an expression for
a sequence of evaluations at run time. Something statements
are used for in many other languages.

In LISP languages, there really is no such distinction,
there only are nested lists in the source code (S-expressions).
But some lists are more like statements, other more like expressions.

In Assembler, there only are simple operations, which are more
like statements.

In pure functional languages, there are no statements nor
sequences of evaluations.

In natural language (English), there are noun phrases and
verb phrases, which approximately correspond to expressions
and statements, respectively.
 
M

Martin Gregorie

IntelliJ, at least, has the ability to indent the code according to the
nesting level. This makes missing or superfluous braces obvious.

It also indicates the matching brace by momentarily highlighting it.
I like that, the syntax colouring, on-the-fly syntactic and semantic
checks and its refactoring facilities, but I find its straight forward
editing features and cursor movement capabilities disappointing. ymmv,
but IMO its clunky editing really detract from its usability, so much so
that its only marginally better than a non-language-aware editor.
 
R

Roedy Green

What editor do you use? Most editors designed
for coding should have a feature "find matching
paranthese/brace/bracket/...".
In vi, it's "%". I've seen it in ultraedit as well
(but don't remember the keyboard shortcut) and
I'd be surprised, if eclipse and netbeans didn't
have such a feature.

I have such features both in SlickEdit and Intellij Idea. However,
the other { is usually not on screen. So this feature is not all that
useful. For it to work I would need a giant screen, perhaps a metre
square where I could pretty well always fit an entire class on the
screen at once.

I think you should be able to label {} so that if they get out of
whack some pretty primitive intelligence can figure out where the
problem is and automatically fix it.

For example if {} used to bracket a method were somehow "stronger"
than ordinary {} your mismatchings would be confined to a method.
 
R

Roedy Green

IntelliJ, at least, has the ability to indent the code according to
the nesting level. This makes missing or superfluous braces obvious.

catch 22. If you run the reformat when {} are not balanced it REALLY
screws up the code. I don't use the feature until I have a clean
compile, which makes it useless for helping find {} balance errors.
 
R

Roedy Green

I would guess it just never occurred to them. The model of statements and
expressions, with the former containing the latter but not vice versa, is
a very ancient one, that has generally served us pretty well.

FORTH makes no such distinction. You can save a value at any point in
the evaluation of an expression. Assignment is just another operator,
conceptually no different from +.

On of the very first languages I used was called Act V,
a sort of primitive FORTRAN which ran on an LGP-30 computer with
tubes, a rotating drum, and no RAM. It too made no distinction.

I can't think of any assembler, other that PL-360 that treats
assignment as a special operator.

So for me, treating assignment as special seems a bit odd, the reverse
of most people.

Granted FORTRAN, COBOL, Basic , PL-1, Pascal and C were very
statement oriented.
 
M

magloca

Roedy Green @ Saturday 30 August 2008 08:45:
catch 22. If you run the reformat when {} are not balanced it REALLY
screws up the code. I don't use the feature until I have a clean
compile, which makes it useless for helping find {} balance errors.

But isn't that the point? I mean, doesn't it screw up the code in such a
way as to easily let you see where the unmatched braces are? And then
indent the code nicely again if you reformat after having fixed the
braces? I have never used IntelliJ, but Eclipse does this pretty well.

m.
 
L

Lars Enderin

Roedy said:
I can't think of any assembler, other that PL-360 that treats
assignment as a special operator.
I wouldn't call the PL360 compiler an assembler. I added the "=:"
operator to PL360 and added a macro processor to the compiler, before we
used it to implement a SIMULA 67 compiler and runtime in 1970-71. The =:
was used in assignments to place intermediate results in registers.
 
M

Mike Schilling

Roedy said:
catch 22. If you run the reformat when {} are not balanced it REALLY
screws up the code.

Then you find the missing/extra brace, insert/delete it properly, and
the code goes back to where it shouild be..
 
J

John W Kennedy

Roedy said:
I can't think of any assembler, other that PL-360 that treats
assignment as a special operator.

I actually have heard people complain that S/360 store instructions
reverse the usual right-to-left flow.
 
R

Roedy Green

But isn't that the point? I mean, doesn't it screw up the code in such a
way as to easily let you see where the unmatched braces are?

It screws up the code in way that if you fix the problem then run
reformat again it will take another 10 minutes to tidy it up all the
inappropriate line breaks it adds. You have to undo the reformat, then
correct the error. The problem is I used to tidy and not notice the
screw up, until later when it was too late to undo, since there were
too many legit changes since.

You could use it if you always found the problem then immediately did
an undo.

My conservative strategy is to avoid reformat except after a clean
compile.
 
R

Roedy Green

Then you find the missing/extra brace, insert/delete it properly, and
the code goes back to where it shouild be..

Try inserting an extra brace. Then reformat. All following code will
have silly line breaks inserted at every ( ). This may be a function
of how you configure the reformatter.
 
T

Tom Anderson

FORTH makes no such distinction. You can save a value at any point in
the evaluation of an expression. Assignment is just another operator,
conceptually no different from +.

On of the very first languages I used was called Act V,
a sort of primitive FORTRAN which ran on an LGP-30 computer with
tubes, a rotating drum, and no RAM. It too made no distinction.

I can't think of any assembler, other that PL-360 that treats
assignment as a special operator.

So for me, treating assignment as special seems a bit odd, the reverse
of most people.

Granted FORTRAN, COBOL, Basic , PL-1, Pascal and C were very
statement oriented.

I wasn't trying to say that all languages have been this way. As you and
Stefan point out, there are many languages that aren't. But Algol was that
way, and thus so was BCPL, C, C++, and the horde of relatives that have
come since. People who grew up in those language traditions may just not
realise things can be any different.

tom
 
M

Mike Schilling

Roedy said:
It screws up the code in way that if you fix the problem then run
reformat again it will take another 10 minutes to tidy it up all the
inappropriate line breaks it adds.

You're using a low-quality IDE then. I've never had that problem with
IntelliJ. Though I don't think I've ever reformatted an entire source
file; just a method (or portion of a method) that's either acquired
unbalanced braces or been significantly modified, say by adding or
removing a try block.
 
M

Mike Schilling

Roedy said:
Try inserting an extra brace. Then reformat. All following code
will
have silly line breaks inserted at every ( ). This may be a
function
of how you configure the reformatter.

It must be, because I've never seen that.
 
R

Roedy Green

You're using a low-quality IDE then. I've never had that problem with
IntelliJ.
I am using Intellij 7.0.4. As I said earlier, the difference in
behaviour is probably because we don't have it configured the same
way. The odds of both of us having it configured the same way are
astronomically small because they are so many things you can tweak.
 

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,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top