<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.1.2" -->
<rss version="2.0" 
	xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
	<title>Comments on: Ruby is dynamically AND strongly typed</title>
	<link>http://www.rubyfleebie.com/ruby-is-dynamically-and-strongly-typed/</link>
	<description>Because programming should be fun</description>
	<pubDate>Sat, 22 Nov 2008 07:23:01 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.1.2</generator>

	<item>
		<title>By: OJ</title>
		<link>http://www.rubyfleebie.com/ruby-is-dynamically-and-strongly-typed/#comment-292</link>
		<author>OJ</author>
		<pubDate>Tue, 10 Jul 2007 03:53:46 +0000</pubDate>
		<guid>http://www.rubyfleebie.com/ruby-is-dynamically-and-strongly-typed/#comment-292</guid>
					<description>&lt;blockquote&gt;   1.
      x = call_function_that_returns_the_number_3_in_the_string_form;
   2.
      y = x + 1 //The programmer expect that "y" will equal 4 (Tee hee hee!)&lt;/blockquote&gt;
Bad example. Noone in their right mind returns numerical values as strings from functions. If the function should return a number, then return a number, not a number as a string.

If in a particular case the programmer knew that the value was going to be a number contained in a string, then he/she would make sure that the value is cast to the right type before proceeding.

What &lt;em&gt;can&lt;/em&gt; happen in a language, and what &lt;em&gt;does&lt;/em&gt; happen when people are using the language are not always the same thing.</description>
		<content:encoded><![CDATA[<blockquote><p>   1.<br />
      x = call_function_that_returns_the_number_3_in_the_string_form;<br />
   2.<br />
      y = x + 1 //The programmer expect that &#8220;y&#8221; will equal 4 (Tee hee hee!)</p></blockquote>
<p>Bad example. Noone in their right mind returns numerical values as strings from functions. If the function should return a number, then return a number, not a number as a string.</p>
<p>If in a particular case the programmer knew that the value was going to be a number contained in a string, then he/she would make sure that the value is cast to the right type before proceeding.</p>
<p>What <em>can</em> happen in a language, and what <em>does</em> happen when people are using the language are not always the same thing.</p>
]]></content:encoded>
				</item>
	<item>
		<title>By: Mr Funk</title>
		<link>http://www.rubyfleebie.com/ruby-is-dynamically-and-strongly-typed/#comment-293</link>
		<author>Mr Funk</author>
		<pubDate>Tue, 10 Jul 2007 05:09:54 +0000</pubDate>
		<guid>http://www.rubyfleebie.com/ruby-is-dynamically-and-strongly-typed/#comment-293</guid>
					<description>1.
      x = "3"
   2.
      y = x + 3 #Wooo! Ruby won’t like that

Won't y = "33" ?</description>
		<content:encoded><![CDATA[<p>1.<br />
      x = &#8220;3&#8243;<br />
   2.<br />
      y = x + 3 #Wooo! Ruby won’t like that</p>
<p>Won&#8217;t y = &#8220;33&#8243; ?</p>
]]></content:encoded>
				</item>
	<item>
		<title>By: Mr Funk</title>
		<link>http://www.rubyfleebie.com/ruby-is-dynamically-and-strongly-typed/#comment-294</link>
		<author>Mr Funk</author>
		<pubDate>Tue, 10 Jul 2007 05:12:10 +0000</pubDate>
		<guid>http://www.rubyfleebie.com/ruby-is-dynamically-and-strongly-typed/#comment-294</guid>
					<description>Hmmm it appears not :(</description>
		<content:encoded><![CDATA[<p>Hmmm it appears not <img src='http://www.rubyfleebie.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /></p>
]]></content:encoded>
				</item>
	<item>
		<title>By: Shalev</title>
		<link>http://www.rubyfleebie.com/ruby-is-dynamically-and-strongly-typed/#comment-295</link>
		<author>Shalev</author>
		<pubDate>Tue, 10 Jul 2007 07:11:08 +0000</pubDate>
		<guid>http://www.rubyfleebie.com/ruby-is-dynamically-and-strongly-typed/#comment-295</guid>
					<description>
class Fixnum
  alias_method :old_plus, :+
  def new_plus(other)
    return  self.to_s + other if other.kind_of? String
    self.old_plus(other)
  end
  alias_method :+, :new_plus
end

x = "3"
y = 3 + x # y now equals "33"

The fact is, that ruby is so dynamic (and I use the term not in its official context) in nature, that strong typing loses much of its punch.  Granted, the default operators will act in a strongly typed manner, but if you took the time to override these operators on the basic primitives (which are really objects/classes), you'd end up with something that looked pretty weakly typed.

It's the best of both worlds, from a coders standpoint.</description>
		<content:encoded><![CDATA[<p>class Fixnum<br />
  alias_method :old_plus, :+<br />
  def new_plus(other)<br />
    return  self.to_s + other if other.kind_of? String<br />
    self.old_plus(other)<br />
  end<br />
  alias_method :+, :new_plus<br />
end</p>
<p>x = &#8220;3&#8243;<br />
y = 3 + x # y now equals &#8220;33&#8243;</p>
<p>The fact is, that ruby is so dynamic (and I use the term not in its official context) in nature, that strong typing loses much of its punch.  Granted, the default operators will act in a strongly typed manner, but if you took the time to override these operators on the basic primitives (which are really objects/classes), you&#8217;d end up with something that looked pretty weakly typed.</p>
<p>It&#8217;s the best of both worlds, from a coders standpoint.</p>
]]></content:encoded>
				</item>
	<item>
		<title>By: Shadowfiend</title>
		<link>http://www.rubyfleebie.com/ruby-is-dynamically-and-strongly-typed/#comment-296</link>
		<author>Shadowfiend</author>
		<pubDate>Tue, 10 Jul 2007 15:25:32 +0000</pubDate>
		<guid>http://www.rubyfleebie.com/ruby-is-dynamically-and-strongly-typed/#comment-296</guid>
					<description>Strong vs weak typing is a very strange and opinion-based argument. There's no real one definition of strong vs weak typing, except that I think most people agree C is weakly typed. For example, you bring up Javascript. Javascript isn't necessarily weakly typed, it just has certain coercion rules so that in certain contexts certain types will be converted to others for compatibility purposes.

To be honest, I think in Ruby, as Shalev pointed out, strong vs weak typing isn't particularly important because of the dynamic nature of the language.</description>
		<content:encoded><![CDATA[<p>Strong vs weak typing is a very strange and opinion-based argument. There&#8217;s no real one definition of strong vs weak typing, except that I think most people agree C is weakly typed. For example, you bring up Javascript. Javascript isn&#8217;t necessarily weakly typed, it just has certain coercion rules so that in certain contexts certain types will be converted to others for compatibility purposes.</p>
<p>To be honest, I think in Ruby, as Shalev pointed out, strong vs weak typing isn&#8217;t particularly important because of the dynamic nature of the language.</p>
]]></content:encoded>
				</item>
	<item>
		<title>By: yriafelc</title>
		<link>http://www.rubyfleebie.com/ruby-is-dynamically-and-strongly-typed/#comment-299</link>
		<author>yriafelc</author>
		<pubDate>Thu, 12 Jul 2007 13:10:36 +0000</pubDate>
		<guid>http://www.rubyfleebie.com/ruby-is-dynamically-and-strongly-typed/#comment-299</guid>
					<description>
x = '3'
x = x + 3 # Error!


but:

Class Fixnum
  def to_str
    self.to_s
  end
end

x = '3'
x = x + 3 # x = '33'
</description>
		<content:encoded><![CDATA[<p>x = &#8216;3&#8242;<br />
x = x + 3 # Error!</p>
<p>but:</p>
<p>Class Fixnum<br />
  def to_str<br />
    self.to_s<br />
  end<br />
end</p>
<p>x = &#8216;3&#8242;<br />
x = x + 3 # x = &#8216;33&#8242;</p>
]]></content:encoded>
				</item>
	<item>
		<title>By: Stephan Schmidt</title>
		<link>http://www.rubyfleebie.com/ruby-is-dynamically-and-strongly-typed/#comment-301</link>
		<author>Stephan Schmidt</author>
		<pubDate>Fri, 13 Jul 2007 08:27:25 +0000</pubDate>
		<guid>http://www.rubyfleebie.com/ruby-is-dynamically-and-strongly-typed/#comment-301</guid>
					<description>Most of those discussions are wrong.

The key concept to grasp in strong versus weak typing is that there is a distinction between reference typing and object typing. Java has static typed references and static typed objects.

Person me = new Person("me")

Both the reference and the object are static typed. People usually call this strong typing.

me = Person.new

Here the reference is dynamic typed and the object is static typed (although in Ruby objects can change their appearance during run-time). Dynamic typed references with static typed objects people usually call weakly typed. 

Groovy is makes the distinction more difficult. It support both dynamic and static references, just as needed.

def me = new Person("me")

and

Person me = new Person("me")

are both legal Groovy code. The first with dynamic typed references and the second with a static typed reference.

I've written extensivly about the distinction more than &lt;a href="http://stephan.reposita.org/archives/2006/03/29/weak-versus-strong-languages-who-wins-the-fight/
"&gt;a year ago&lt;/a&gt;.

Peace
-stephan

-- 
Stephan Schmidt :: stephan@reposita.org
Reposita Open Source - Monitor your software development
http://www.reposita.org 
Blog at http://stephan.reposita.org - No signal. No noise.</description>
		<content:encoded><![CDATA[<p>Most of those discussions are wrong.</p>
<p>The key concept to grasp in strong versus weak typing is that there is a distinction between reference typing and object typing. Java has static typed references and static typed objects.</p>
<p>Person me = new Person(&#8221;me&#8221;)</p>
<p>Both the reference and the object are static typed. People usually call this strong typing.</p>
<p>me = Person.new</p>
<p>Here the reference is dynamic typed and the object is static typed (although in Ruby objects can change their appearance during run-time). Dynamic typed references with static typed objects people usually call weakly typed. </p>
<p>Groovy is makes the distinction more difficult. It support both dynamic and static references, just as needed.</p>
<p>def me = new Person(&#8221;me&#8221;)</p>
<p>and</p>
<p>Person me = new Person(&#8221;me&#8221;)</p>
<p>are both legal Groovy code. The first with dynamic typed references and the second with a static typed reference.</p>
<p>I&#8217;ve written extensivly about the distinction more than <a href="http://stephan.reposita.org/archives/2006/03/29/weak-versus-strong-languages-who-wins-the-fight/<br />
">a year ago</a>.</p>
<p>Peace<br />
-stephan</p>
<p>&#8211;<br />
Stephan Schmidt :: <a href="mailto:stephan@reposita.org">stephan@reposita.org</a><br />
Reposita Open Source - Monitor your software development<br />
<a href="http://www.reposita.org" rel="nofollow">http://www.reposita.org</a><br />
Blog at <a href="http://stephan.reposita.org" rel="nofollow">http://stephan.reposita.org</a> - No signal. No noise.</p>
]]></content:encoded>
				</item>
	<item>
		<title>By: jman</title>
		<link>http://www.rubyfleebie.com/ruby-is-dynamically-and-strongly-typed/#comment-302</link>
		<author>jman</author>
		<pubDate>Fri, 13 Jul 2007 12:54:59 +0000</pubDate>
		<guid>http://www.rubyfleebie.com/ruby-is-dynamically-and-strongly-typed/#comment-302</guid>
					<description>Excellent explanation of a easily misunderstood concept!</description>
		<content:encoded><![CDATA[<p>Excellent explanation of a easily misunderstood concept!</p>
]]></content:encoded>
				</item>
	<item>
		<title>By: Shadowfiend</title>
		<link>http://www.rubyfleebie.com/ruby-is-dynamically-and-strongly-typed/#comment-303</link>
		<author>Shadowfiend</author>
		<pubDate>Fri, 13 Jul 2007 13:59:17 +0000</pubDate>
		<guid>http://www.rubyfleebie.com/ruby-is-dynamically-and-strongly-typed/#comment-303</guid>
					<description>@yriafelc -- yes, but in that situation, you've changed the `unmentioned' semantics of +to_str+ -- namely, that an object that has that method is, for all intents and purposes, a string, while +to_s+ means that it can be represented as one. Personally, I think String#+ should use +to_s+ rather than +to_str+. But then again, that's what string interpolation is for, so whatever.</description>
		<content:encoded><![CDATA[<p>@yriafelc &#8212; yes, but in that situation, you&#8217;ve changed the `unmentioned&#8217; semantics of +to_str+ &#8212; namely, that an object that has that method is, for all intents and purposes, a string, while +to_s+ means that it can be represented as one. Personally, I think String#+ should use +to_s+ rather than +to_str+. But then again, that&#8217;s what string interpolation is for, so whatever.</p>
]]></content:encoded>
				</item>
	<item>
		<title>By: Matt Giuca</title>
		<link>http://www.rubyfleebie.com/ruby-is-dynamically-and-strongly-typed/#comment-304</link>
		<author>Matt Giuca</author>
		<pubDate>Fri, 13 Jul 2007 16:35:16 +0000</pubDate>
		<guid>http://www.rubyfleebie.com/ruby-is-dynamically-and-strongly-typed/#comment-304</guid>
					<description>So from some of these comments (the guy who overloaded Ruby + and the guy who said C is weakly typed) - it seems like we can classify strong/weak as being a property of the OPERATORS themselves, not the type system! (For the most part).

I wouldn't classify C as having a particularly weak type system. It lets you implicitly cast numbers around (eg. (int)3 + (float)4.7 =&#62; (float)7.7), but that's about it. For instance, C won't let you go "3" + 4 and give you 7 - which a truly "weak" type system will give you.

Oh no, C is far worse - it isn't _weak_, it's _unsafe_! The 3rd classification after dynamic/static and weak/strong is safe/unsafe. In C if you do "3" + 4, you get ... a pointer 3 bytes past the end of the string! This is usually unacceptable in modern languages so it doesn't happen in most. But just a point, I wouldn't consider that "weakness".

Sorry for getting off-topic. Oh, a very good article though!</description>
		<content:encoded><![CDATA[<p>So from some of these comments (the guy who overloaded Ruby + and the guy who said C is weakly typed) - it seems like we can classify strong/weak as being a property of the OPERATORS themselves, not the type system! (For the most part).</p>
<p>I wouldn&#8217;t classify C as having a particularly weak type system. It lets you implicitly cast numbers around (eg. (int)3 + (float)4.7 =&gt; (float)7.7), but that&#8217;s about it. For instance, C won&#8217;t let you go &#8220;3&#8243; + 4 and give you 7 - which a truly &#8220;weak&#8221; type system will give you.</p>
<p>Oh no, C is far worse - it isn&#8217;t _weak_, it&#8217;s _unsafe_! The 3rd classification after dynamic/static and weak/strong is safe/unsafe. In C if you do &#8220;3&#8243; + 4, you get &#8230; a pointer 3 bytes past the end of the string! This is usually unacceptable in modern languages so it doesn&#8217;t happen in most. But just a point, I wouldn&#8217;t consider that &#8220;weakness&#8221;.</p>
<p>Sorry for getting off-topic. Oh, a very good article though!</p>
]]></content:encoded>
				</item>
	<item>
		<title>By: Shadowfiend</title>
		<link>http://www.rubyfleebie.com/ruby-is-dynamically-and-strongly-typed/#comment-305</link>
		<author>Shadowfiend</author>
		<pubDate>Sat, 14 Jul 2007 23:34:41 +0000</pubDate>
		<guid>http://www.rubyfleebie.com/ruby-is-dynamically-and-strongly-typed/#comment-305</guid>
					<description>But that's often what's meant with weak. Weak means that there is a weak distinction between the types (more or less). In C, that's particularly evident because you get virtually no distinction between pointer types -- they're all integers at the end of the day, and you can do whatever you want with them. Casting lets you achieve just about anything, with no checking until you get a segfault in your running program :)</description>
		<content:encoded><![CDATA[<p>But that&#8217;s often what&#8217;s meant with weak. Weak means that there is a weak distinction between the types (more or less). In C, that&#8217;s particularly evident because you get virtually no distinction between pointer types &#8212; they&#8217;re all integers at the end of the day, and you can do whatever you want with them. Casting lets you achieve just about anything, with no checking until you get a segfault in your running program <img src='http://www.rubyfleebie.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p>
]]></content:encoded>
				</item>
	<item>
		<title>By: txt &#187; Dynamic/Static/Strong/Weak Types</title>
		<link>http://www.rubyfleebie.com/ruby-is-dynamically-and-strongly-typed/#comment-308</link>
		<author>txt &#187; Dynamic/Static/Strong/Weak Types</author>
		<pubDate>Wed, 25 Jul 2007 18:16:17 +0000</pubDate>
		<guid>http://www.rubyfleebie.com/ruby-is-dynamically-and-strongly-typed/#comment-308</guid>
					<description>[...] Original Article [...]</description>
		<content:encoded><![CDATA[<p>[&#8230;] Original Article [&#8230;]</p>
]]></content:encoded>
				</item>
</channel>
</rss>
