--e89a8f13ec6650536e04bfa6f0d5
Content-Type: text/plain; charset=ISO-8859-1

On Wed, May 9, 2012 at 9:37 PM, sam jam <lists / ruby-forum.com> wrote:

> def first
>    name  sam"
>    last(name)
>  end
>
>   def last(first)
>     name  irst + " " + "jam"
>   end
>
> versus
>
>  def first
>    @name  sam"
>    last
>  end
>
>   def last
>     name  name + " " + "jam"
>   end
>
> I am new to ruby and programming. I see that both of these ways work.
> When I was first starting I tended toward the first way, but lately I
> have
> been tending toward the second way. Does it make much difference?
>
> edit: saying brand n-3-w means my post contains spam? lol...okay first
> starting then.
>
>
Hi, Sam, good question :)

Unfortunately the answer is the ever-nebulous "it depends" :P

Within an object, the second way is generally better, because objects
should generally be small and operate on a shared set of instance variables.

Outside an object (e.g., in this case these methods are declared on main --
which is technically an object, but its purpose isn't to interact with your
system so much as to give you an environment to wire your stuff together
and bootstrap your app in), the former is usually better.

I'd like to go further into this, but it's a bit difficult as the names of
the methods don't accurately reflect what they do (these both return full
names, last is just a helper that first calls in order to concatenate the
names)

--e89a8f13ec6650536e04bfa6f0d5
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

On Wed, May 9, 2012 at 9:37 PM, sam jam <span dir="ltr">&lt;<a href="mailto:lists / ruby-forum.com" target="_blank">lists / ruby-forum.com</a>&gt;</span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
def first<br>
    婼  
<br>
 def last(first)<br>
 name = first + &quot; &quot; + &quot;jam&quot;<br>
 end<br>
<br>
versus<br>
<br>
          
<br>
 def last<br>
 name = @name + &quot; &quot; + &quot;jam&quot;<br>
 end<br>
<br>
I am new to ruby and programming. I see that both of these ways work.<br>
When I was first starting I tended toward the first way, but lately I<br>
have<br>
been tending toward the second way. Does it make much difference?<br>
<br>
edit: saying brand n-3-w means my post contains spam? lol...okay first<br>
starting then.<br><br></blockquote><div><br></div><div>Hi, Sam, good question :)</div><div><br></div><div>Unfortunately the answer is the ever-nebulous &quot;it depends&quot; :P</div><div><br></div><div>Within an object, the second way is generally better, because objects should generally be small and operate on a shared set of instance variables.</div>
<div><br></div><div>Outside an object (e.g., in this case these methods areeclared on main -- which is technically an object, but its purpose isn&#39;t to interact with your system so much as to give you an environment to wire your stuff together and bootstrap your app in), the former is usually better.</div>
<div><br></div><div>I&#39;d like to go further into this, but it&#39;s a bit difficult as the names of the methods don&#39;t accurately reflect what they do (these both return full names, last is just a helper that first calls in order to concatenate the names)</div>
</div>

--e89a8f13ec6650536e04bfa6f0d5--