# Is there any nomenclature for private methods?

**URL:** <https://www.ruby-forum.com/t/is-there-any-nomenclature-for-private-methods/135797>\
**Category:** Ruby\
**Created:** [April 25, 2008, 1:50am UTC](https://www.ruby-forum.com/t/is-there-any-nomenclature-for-private-methods/135797 "2008-04-25T01:50:23Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![ISSSSaki\_Baz\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/51bf81/32.png) [@ISSSSaki\_Baz\_C](https://www.ruby-forum.com/u/ISSSSaki_Baz_C)\
**Post date:** [April 25, 2008, 1:50am UTC](https://www.ruby-forum.com/t/is-there-any-nomenclature-for-private-methods/135797/1 "2008-04-25T01:50:23Z")

</div>

Hi, I don’t like the way of declaring publi and private methods since  
it’s not  
really clear. AFAIK there are you ways:

1. 

class C  
def public\_1  
end

def public\_2  
end

private:  
def private\_1  
end

public:  
def public\_3  
end

or:

1. 

class C  
def public\_1  
end

def public\_2  
end

def private\_1  
end

def public\_3

private :private\_1  
end

I prefer 2) but until the end of class it’s not easy to know if a method  
is  
public or private/protected. So i’m thinking about use a special  
nomenclature  
for private methods, for example:

def \_private\_1

Is there any “standar” for this? I’ve seen lost of ethods called  
“ **xxxx** ”  
or “\_xxxxx” but not sure the reason of that name.

Thanks a lot.

---

<div class="post-metadata">

**Author:** ![ISSSSaki\_Baz\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/51bf81/32.png) [@ISSSSaki\_Baz\_C](https://www.ruby-forum.com/u/ISSSSaki_Baz_C)\
**Post date:** [April 25, 2008, 3:22am UTC](https://www.ruby-forum.com/t/is-there-any-nomenclature-for-private-methods/135797/2 "2008-04-25T03:22:46Z")

</div>

On Apr 24, 7:49 pm, Iñaki Baz C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> 1. 
> 
> ```
> def public_3
> 
> private :private_1
> 
> ```
> 
> end

One way is do it immediately after the method. E.g.

```
     def private_1
     end
     private :private_1

     def public_3
     end

```

I’ve seen other coders use the declarations before every single method  
regardless

```
     public
     def public_2
     end

     private
     def private_1
     end

     public
     def public_3
     end

```

I agree that these declarations are one of the “sore-eyes” of Ruby,  
but what else can be done? Matz has always seemed against allowing:

private def foo()  
end

In many ways it’s really not important though. A more Ruby-esque way  
in my opinion is to just make them all public and document them  
appropriately. There is the exception of method\_missing’s behavior  
however.

> I prefer 2) but until the end of class it’s not easy to know if a method is  
> public or private/protected. So i’m thinking about use a special nomenclature  
> for private methods, for example:
> 
> ```
> def _private_1
> 
> ```
> 
> Is there any “standar” for this? I’ve seen lost of ethods called “ **xxxx** ”  
> or “\_xxxxx” but not sure the reason of that name.

An initial underscore or double underscore basically indicates  
“special/avoid overwrite” --meaning it’s meant to reduce the  
likelihood that someone else might define a method/attribute of the  
same name. The most common occurrence is **send**.

T.

---

<div class="post-metadata">

**Author:** ![ISSSSaki\_Baz\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/51bf81/32.png) [@ISSSSaki\_Baz\_C](https://www.ruby-forum.com/u/ISSSSaki_Baz_C)\
**Post date:** [April 25, 2008, 3:25am UTC](https://www.ruby-forum.com/t/is-there-any-nomenclature-for-private-methods/135797/3 "2008-04-25T03:25:07Z")

</div>

On Apr 24, 2008, at 16:49 , Iñaki Baz C. wrote:

> “ **xxxx** ”  
> or “\_xxxxx” but not sure the reason of that name.

I don’t ever use private or protected, but I do use that naming  
convention to convey the notion. Don’t use double-underscore, that’s  
basically considered reserved.

def \_think\_twice\_before\_calling  
…  
end

---

<div class="post-metadata">

**Author:** ![ISSSSaki\_Baz\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/51bf81/32.png) [@ISSSSaki\_Baz\_C](https://www.ruby-forum.com/u/ISSSSaki_Baz_C)\
**Post date:** [April 25, 2008, 12:19pm UTC](https://www.ruby-forum.com/t/is-there-any-nomenclature-for-private-methods/135797/4 "2008-04-25T12:19:09Z")

</div>

2008/4/25, Trans [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> I agree that these declarations are one of the “sore-eyes” of Ruby,  
> but what else can be done? Matz has always seemed against allowing:
> 
> private def foo()  
> end

Thanks, surely I’ll use:

def \_private\_method\_1  
…  
end  
private : \_provate\_mehtod\_1

> In many ways it’s really not important though. A more Ruby-esque way  
> in my opinion is to just make them all public and document them  
> appropriately.

But if you do a framework other people to programme in it maybe is  
neccesary to abstract the API and use private methods as security,  
isn’t?

> An initial underscore or double underscore basically indicates  
> “special/avoid overwrite” --meaning it’s meant to reduce the  
> likelihood that someone else might define a method/attribute of the  
> same name. The most common occurrence is **send**.

Ok understood 😉

---

<div class="post-metadata">

**Author:** ![ISSSSaki\_Baz\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/51bf81/32.png) [@ISSSSaki\_Baz\_C](https://www.ruby-forum.com/u/ISSSSaki_Baz_C)\
**Post date:** [April 25, 2008, 2:03pm UTC](https://www.ruby-forum.com/t/is-there-any-nomenclature-for-private-methods/135797/5 "2008-04-25T14:03:51Z")

</div>

Hi,

On Fri, Apr 25, 2008 at 8:18 PM, IÃ±aki Baz C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> But if you do a framework other people to programme in it maybe is  
> neccesary to abstract the API and use private methods as security,  
> isn’t?

But they’ve got your code anyway. They can see it and modify it if they  
choose (for example.. replacing all `private's with `public’s.. then  
what?).  
Also, note you can always use `send’ to get around protection:

> > class Something  
> > private  
> > def hi  
> > puts “Oops!”  
> > end  
> > end  
> > =\> nil  
> > s = Something.new  
> > =\> #Something:0xb7a09274  
> > s.hi  
> > NoMethodError: private method `hi’ called for #Something:0xb7a09274  
> > from (irb):10  
> > s.send :hi  
> > Oops!  
> > =\> nil

Abstracting the API is a good point, but perhaps they should be  
disconnected  
in a manner other than using private/protected methods…

Cheers,  
Arlen

---

<div class="post-metadata">

**Author:** ![ISSSSaki\_Baz\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/51bf81/32.png) [@ISSSSaki\_Baz\_C](https://www.ruby-forum.com/u/ISSSSaki_Baz_C)\
**Post date:** [April 25, 2008, 2:45pm UTC](https://www.ruby-forum.com/t/is-there-any-nomenclature-for-private-methods/135797/6 "2008-04-25T14:45:57Z")

</div>

2008/4/25, Arlen C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> Also, note you can always use `send’ to get around protection:

I’ve read somewhere that Ruby 1.9 doesn’t allow it.

---

<div class="post-metadata">

**Author:** ![ISSSSaki\_Baz\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/51bf81/32.png) [@ISSSSaki\_Baz\_C](https://www.ruby-forum.com/u/ISSSSaki_Baz_C)\
**Post date:** [April 25, 2008, 3:24pm UTC](https://www.ruby-forum.com/t/is-there-any-nomenclature-for-private-methods/135797/7 "2008-04-25T15:24:55Z")

</div>

Hi,

On Fri, Apr 25, 2008 at 10:45 PM, IÃ±aki Baz C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> 2008/4/25, Arlen C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):
> 
> > Also, note you can always use `send’ to get around protection:
> 
> I’ve read somewhere that Ruby 1.9 doesn’t allow it.

[eigenclass - Changes in Ruby 1.9](http://eigenclass.org/hiki.rb?Changes+in+Ruby+1.9#l24)

send!, then. 🙂

There’s an absolute monster of a thread about how this was named (from  
'05)  
starting here:

[http://blade.nagaokaut.ac.jp/cgi-bin/vframe.rb/ruby/ruby-talk/153672?153666-154682+split-mode-vertical](http://blade.nagaokaut.ac.jp/cgi-bin/vframe.rb/ruby/ruby-talk/153672?153666-154682+split-mode-vertical)

Arlen

---

<div class="post-metadata">

**Author:** ![ISSSSaki\_Baz\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/51bf81/32.png) [@ISSSSaki\_Baz\_C](https://www.ruby-forum.com/u/ISSSSaki_Baz_C)\
**Post date:** [April 25, 2008, 4:10pm UTC](https://www.ruby-forum.com/t/is-there-any-nomenclature-for-private-methods/135797/8 "2008-04-25T16:10:45Z")

</div>

Hi –

On Fri, 25 Apr 2008, Arlen C. wrote:

> Hi,

On Fri, Apr 25, 2008 at 10:45 PM, IÃ±aki Baz C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> 2008/4/25, Arlen C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):
> 
> > Also, note you can always use `send’ to get around protection:
> 
> I’ve read somewhere that Ruby 1.9 doesn’t allow it.

[eigenclass - Changes in Ruby 1.9](http://eigenclass.org/hiki.rb?Changes+in+Ruby+1.9#l24)

send!, then. 🙂

Unfortunately (in my opinion), I believe that’s been reverted, so that  
#send will be what it always has been and a new method, #public\_send,  
will be send that only works on public methods.

David

---

<div class="post-metadata">

**Author:** ![ISSSSaki\_Baz\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/51bf81/32.png) [@ISSSSaki\_Baz\_C](https://www.ruby-forum.com/u/ISSSSaki_Baz_C)\
**Post date:** [April 25, 2008, 4:20pm UTC](https://www.ruby-forum.com/t/is-there-any-nomenclature-for-private-methods/135797/9 "2008-04-25T16:20:47Z")

</div>

On Apr 25, 2008, at 16:09 , David A. Black wrote:

> Unfortunately (in my opinion), I believe that’s been reverted, so that  
> #send will be what it always has been and a new method, #public\_send,  
> will be send that only works on public methods.

The Ruby P.ming Language says so on page 274.

---

<div class="post-metadata">

**Author:** ![ISSSSaki\_Baz\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/51bf81/32.png) [@ISSSSaki\_Baz\_C](https://www.ruby-forum.com/u/ISSSSaki_Baz_C)\
**Post date:** [April 25, 2008, 4:40pm UTC](https://www.ruby-forum.com/t/is-there-any-nomenclature-for-private-methods/135797/10 "2008-04-25T16:40:22Z")

</div>

On Thu, Apr 24, 2008 at 9:24 PM, Ryan D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> I don’t ever use private or protected, but I do use that naming convention  
> to convey the notion. Don’t use double-underscore, that’s basically  
> considered reserved.
> 
> def \_think\_twice\_before\_calling  
> …  
> end

Good lord, one of the [smaller] reasons I enjoy coding Ruby over  
Python is avoiding that kind of ugliness. May I ask _why_ you would  
prefer that over real private/protected?

–  
Avdi

Home: [http://avdi.org](http://avdi.org)  
Developer Blog: [avdi.codes – Avdi Grimm, Code Cleric](http://avdi.org/devblog/)  
Twitter: [http://twitter.com/avdi](http://twitter.com/avdi)  
Journal: [http://avdi.livejournal.com](http://avdi.livejournal.com)

---

<div class="post-metadata">

**Author:** ![ISSSSaki\_Baz\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/51bf81/32.png) [@ISSSSaki\_Baz\_C](https://www.ruby-forum.com/u/ISSSSaki_Baz_C)\
**Post date:** [May 1, 2008, 9:05pm UTC](https://www.ruby-forum.com/t/is-there-any-nomenclature-for-private-methods/135797/11 "2008-05-01T21:05:12Z")

</div>

On Apr 25, 2008, at 07:38 , Avdi G. wrote:

> Good lord, one of the [smaller] reasons I enjoy coding Ruby over  
> Python is avoiding that kind of ugliness. May I ask _why_ you would  
> prefer that over real private/protected?

1. makes testing easier / cleaner.

2. there IS no real private/protected. Just try to keep me out if I  
want in.

---

<div class="post-metadata">

**Author:** ![ISSSSaki\_Baz\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/51bf81/32.png) [@ISSSSaki\_Baz\_C](https://www.ruby-forum.com/u/ISSSSaki_Baz_C)\
**Post date:** [April 25, 2008, 3:56pm UTC](https://www.ruby-forum.com/t/is-there-any-nomenclature-for-private-methods/135797/12 "2008-04-25T15:56:29Z")

</div>

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

On Apr 25, 2008, at 2:03 PM, Arlen C. wrote:

> > >
> 
> Abstracting the API is a good point, but perhaps they should be  
> disconnected  
> in a manner other than using private/protected methods…
> 
> Cheers,  
> Arlen

Actually, I see private and protected as hint of intension. Even in  
Java, you can circumvent them.

The method is private =\> it’s for internal use - so don’t cry if it  
gets changed in some minor version, you should not rely on it anyway.  
So if you really, really have to use **send** , know the consequences.

Regards,  
Florian G.  
-----BEGIN PGP SIGNATURE-----  
Version: GnuPG v1.4.8 (Darwin)

iEYEARECAAYFAkgR4rsACgkQJA/zY0IIRZYwpgCbB0QxAxv1sT7d4KP/gbWKqyvL  
IFIAn2zmRT2OWz9cY/7PWJokRsUu4lbh  
=1jKc  
-----END PGP SIGNATURE-----
