Method naming convention required

X

Xagyg

Xagyg said:
In Ruby, a method that modifies the instance using it is suffixed with
a '!'.

E.g. someString.reverse() returns a String with a reversed result,
however, someString.reverse! reverses the result of someString.

Does anyone have/use/know of a method-naming convention in Java to
distinguish between methods that modify the instance and methods that
don't?

Feel free to suggest one if you like.

One idea would be to prefix or suffix one of the methods with an
underscore. I'll think about that too. Not sure which one.... Following
Ruby, I could suffix the destructive method with an underscore.

e.g. Set union(Set s) - non-destructive - i.e. returns the result as
a Set
boolean union_ (Set s) - updates "this" (returns true if "this"
set changed).
 
X

Xagyg

One idea would be to prefix or suffix one of the methods with an
underscore. I'll think about that too. Not sure which one.... Following
Ruby, I could suffix the destructive method with an underscore.

e.g. Set union(Set s) - non-destructive - i.e. returns the result as
a Set
boolean union_ (Set s) - updates "this" (returns true if "this"
set changed).

Can we vote... use _ as suffix as per Ruby exclamation '!'
or judicious use of method names?

e.g. Set union(Set s)
boolean setUnionWith(Set s)

another e.g. of naming:

"Ruby" method: domainRestriction and domainRestriction_
"Name" method: domainRestriction and restrictDomainBy

?????

Votes?
 
L

Lasse Reichstein Nielsen

John W. Kennedy said:
It's a Rubyism.

It's a notation that has also been used in other, earlier, languages,
e.g., Scheme.
(set! x (integer? y)) ; read: set-bang x to integer-huh y :)

I don't know much about Ruby, but it seems they have stolen liberally
from Scheme and probably also other languages.

/L 'Genious is stealing from the right people, plagarism is stealing
from the wrong'
 
J

John W. Kennedy

Lasse said:
It's a notation that has also been used in other, earlier, languages,
e.g., Scheme.
(set! x (integer? y)) ; read: set-bang x to integer-huh y :)

I don't know much about Ruby, but it seems they have stolen liberally
from Scheme and probably also other languages.

SmallTalk's "everything is an object" philosophy plus lambdas and
closures from LISP plus some Ada syntax plus Perl's core functionality
plus a mania for duck typing. I quite like it as a Perl replacement --
in fact, I ported all my personal Perl utilities to Ruby -- but I'm too
old to accept the attitude of too many Rubyists that Ruby is a perfectly
good replacement for Java or even C "because CPU time doesn't matter
anymore".
 
D

Doug Pardee

Patricia said:
Is a Fortran function that modifies a common block a side-effect function?

Of course. For that matter, a FORTRAN function could modify its
parameters (call by reference and all that). Which is why I noted that
"Most languages couldn't actually stop you from putting a side effect
into a function definition". But in most cases it was discouraged
because you didn't know what the compiler would do when optimizing the
function calls; the compilers generally treated function calls as being
idempotent and side-effect free.

But with C, side-effect functions became fully legitimized. The C
standard library includes zillions (approximately) of intentional
side-effect functions. Oh, and I shouldn't forget to mention the
side-effect operators ++ and --. Then along came "const" to try to
patch up some of the mess that got created.

That's all ancient history now, though. Java is what it is. But I still
recommend separating the imperative from the applicative. Albeit with
the occasional dalliance with the likes of the "pop" method for stacks.
 
C

Chris Uppal

[We're getting way off-topic here, but what the hell ? It's only Monday...]
SmallTalk's "everything is an object" philosophy plus lambdas and
closures from LISP plus some Ada syntax plus Perl's core functionality
plus a mania for duck typing.

Not only "everything is an object" from Smalltalk (note spelling) but Ruby's
blocks are essentially the same (if you ignore some wierd chunkiness) as
Smalltalk's. Mixins from CLOS (etc). Obfuscatory syntax from Perl (;-)...

I quite like it as a Perl replacement --
in fact, I ported all my personal Perl utilities to Ruby -- but I'm too
old to accept the attitude of too many Rubyists that Ruby is a perfectly
good replacement for Java or even C "because CPU time doesn't matter
anymore".

I find it odd, too, that the Ruby (and some other scripty languages'
enthusiasts) are so willing to claim it doesn't matter. I may be cynical, but
I suspect that if they ever get decent VM technology (as has, of course, been
available for /ages/ in languages with semantics at least as dynamic and
flexible as Ruby's) then they'd suddenly start touting performance as a
necessity, or at least as /highly/ desirable...

-- chris
 
C

Chris Uppal

Xagyg said:
One idea would be to prefix or suffix one of the methods with an
underscore. I'll think about that too. Not sure which one.... Following
Ruby, I could suffix the destructive method with an underscore.

If you want any of the following:

- your software to be used by other people;

- your software to be a good advertisement of your skills to potential
employers;

- your own coding habits to be compatible with other people's;

then don't do it. Don't even /consider/ doing it.

Of course, you could follow Stefan's example and write your own code in (I mean
no offence) "abnormal" Java, following whatever personal conventions you like,
and use a preprocessor to create the public version of the code from that.
Seems a lot of effort for little or no gain to me, but YMMV.

-- chris
 
H

Hendrik Maryns

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Xagyg schreef:
Can we vote... use _ as suffix as per Ruby exclamation '!'
or judicious use of method names?

e.g. Set union(Set s)
boolean setUnionWith(Set s)

another e.g. of naming:

"Ruby" method: domainRestriction and domainRestriction_
"Name" method: domainRestriction and restrictDomainBy

Name.

H.
- --
Hendrik Maryns
http://tcl.sfs.uni-tuebingen.de/~hendrik/
==================
http://aouw.org
Ask smart questions, get good answers:
http://www.catb.org/~esr/faqs/smart-questions.html
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)

iD8DBQFFPIlse+7xMGD3itQRAjhMAJ9ssxYCEHHLw5j2c3naSXeE3YOb2gCeJs32
Pey2pSCJeRKa6pYnwpDzT9g=
=ouR8
-----END PGP SIGNATURE-----
 
E

Ed

Xagyg skrev:
Can we vote... use _ as suffix as per Ruby exclamation '!'
or judicious use of method names?

e.g. Set union(Set s)
boolean setUnionWith(Set s)

another e.g. of naming:

"Ruby" method: domainRestriction and domainRestriction_
"Name" method: domainRestriction and restrictDomainBy

?????

Votes?

..ed

Name.

Computer languages are complicated proportional to the number of
non-alphanumeric characters they employ.

And yes, I'm looking at you, < and >.
 
S

Simon Brooke

Lasse Reichstein Nielsen said:
It's a notation that has also been used in other, earlier, languages,
e.g., Scheme.
(set! x (integer? y)) ; read: set-bang x to integer-huh y :)

And in earlier LISPs, predicate functions typically had names ending in P,
as in CONSP.

--
(e-mail address removed) (Simon Brooke) http://www.jasmine.org.uk/~simon/

;; Human history becomes more and more a race between
;; education and catastrophe.
H.G. Wells, "The Outline of History"
 
B

Bent C Dalager

I find it odd, too, that the Ruby (and some other scripty languages'
enthusiasts) are so willing to claim it doesn't matter. I may be cynical, but
I suspect that if they ever get decent VM technology (as has, of course, been
available for /ages/ in languages with semantics at least as dynamic and
flexible as Ruby's) then they'd suddenly start touting performance as a
necessity, or at least as /highly/ desirable...

I expect that for so long as Ruby is "slow", it gets used for tasks
where slowness is acceptable and with this taken into account, the
Rubyists would be quite correct: it doesn't matter if it's slow.

If Ruby should ever get a decent VM to speed it up, people would start
using it for tasks where speed is important and when this happens,
well, of course they will start claiming speed as desirable, because
it will be :)


(Disclaimer: I know next to nothing about Ruby and have no idea
whether it actually _is_ slow or not.)

Cheers
Bent D
 
J

John W. Kennedy

Bent said:
(Disclaimer: I know next to nothing about Ruby and have no idea
whether it actually _is_ slow or not.)

As a rough rule of thumb, it takes about 130%-150% as long to do
something in Ruby as in Perl. There are exceptions, however. I wrote a
set of perfect-number finders where Ruby is much, much faster than Perl,
and also faster than Java (I suspect the BigInteger class in Java may
need a tweak). GCLISP is faster than any of them.
 

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,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top