Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

:rolling: Innovative functions !!!

 
raja kanak
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


The above code compiles & runs fine.
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please tell us the point you are trying to make.
Moving into Java In General (Beginner)....
[ March 07, 2007: Message edited by: Barry Gaunt ]
 
Rao Raghu
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Now it doesn't compile. Shows errors as follows:


 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey, I'm surprised that compiled at all. I can't tell if you were confused by it or amused for the same reason I was surprised - class names are not reserved words.

For example:

defines a method with a single argument of type String and name String.

This line

is looking for a method with two String arguments like

with two arguments of type String, named one and two.

One can write pretty silly looking programs in REXX, too. It has no reserved words, only keywords in context. This says "5" three times:

Not a recommended style.

[ March 07, 2007: Message edited by: Stan James ]
[ March 07, 2007: Message edited by: Stan James ]
 
Rao Raghu
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Now it compiles.

output is:


 
Rao Raghu
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Stan James:
I can't tell if you were confused by it or amused for the same reason I was surprised - class names are not reserved words.


Isn't this a kind of a drawback of java which eats into the readability of the code? An example is the class shown in this thread


 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64629
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Rao Raghu:
Isn't this a kind of a drawback of java which eats into the readability of the code?


I would say that it would reflect badly on the author of such code more so than the language itself.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The way we usually avoid that is: class names start with a capital letter, variable names do not. So something like

Class class = Class.getClass();

is perfectly clear.

Time shifting compilers are very difficult so only the most advanced languages prevent you from making a variable name match the name of a class that you haven't written yet. They also warn if you write a bug that will be found later. Tony could probably fill us in on those.

Ok, it's not quite 4/1.
 
Campbell Ritchie
Sheriff
Posts: 48406
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Class class = Class.getClass();
Not quite. You have forgotten that "class" is a keyword (and reserved work).
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Right you are. I really hate seeing variables named clazz and clzzzz so I should have remembered that.
 
Rao Raghu
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Stan James:
class names start with a capital letter, variable names do not


This is just a convention. Even otherwise the class will compile and run fine. We are not bound in any way to follow the convention. The bottom-line is 'why should the language allow us to use class names as variable names in the first place?'



 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Rao Raghu:


This is just a convention. Even otherwise the class will compile and run fine. We are not bound in any way to follow the convention. The bottom-line is 'why should the language allow us to use class names as variable names in the first place?'





The language allows us to do all sorts of things that are unhelpful, bad, dangerous, difficult to maintain, stupid, pointless, confusing etc. This is true of all programming languages. As Bear has already said, this really reflects badly on the programmer not the language. If you give someone a hammer and he uses it to hit himself on the head, is it the hammer's fault he's able to hurt himself?
[ March 12, 2007: Message edited by: Paul Sturrock ]
 
Rao Raghu
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Paul Sturrock
If you give someone a hammer and he uses it to hit himself on the head, is it the hammer's fault he's able to hurt himself?


I got your point , Paul.


 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic