• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

:rolling: Innovative functions !!!

 
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


The above code compiles & runs fine.
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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


 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Now it compiles.

output is:


 
Rao Raghu
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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


 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Stan James
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?'



 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.


 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic