论坛首页 编程语言技术论坛

ruby 和 c# 3.0

浏览 8670 次
锁定老帖子 主题:ruby 和 c# 3.0
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2007-07-02  
看了C# 3.0 的feature, 瀑布汗了一下,MS 开始抄Ruby了么
有下例为证
c# 3.0
c# 代码
 
  1. 10.Times((int i) =>  
  2.                 {  
  3.                     if (i > 5)  
  4.                         Console.WriteLine(i);  
  5.                     else  
  6.                         Console.WriteLine("less than five");  
  7.                 }  
  8.               );  
ruby:
ruby 代码
 
  1. 10.times {|i| puts i.to_s}  

还有
c# 代码
 
  1. var dt = 1.Years().Ago();  
  2.   
  3. var dt2 = 1.Minutes().Ago();  
  4.   
  5. Console.WriteLine("one year age:" + dt.ToShortDateString());  
  6. Console.WriteLine("one minute age:" + dt2.ToString());  

具体实现如下:
c# 代码
 
  1. public static class NumericExtention  
  2.    {  
  3.        public static int Years(this int value)  
  4.        {  
  5.            return value * 60 * 60  * 24 *365;  
  6.        }  
  7.   
  8.        public static int Seconds(this int value)  
  9.        {  
  10.            return value;  
  11.        }  
  12.   
  13.        public static int Minutes(this int value)  
  14.        {  
  15.            return value * 60;  
  16.        }  
  17.   
  18.        public static int Hours(this int value)  
  19.        {  
  20.            return value * 60 * 60;  
  21.        }  
  22.   
  23.        public static DateTime Ago(this int value)  
  24.        {  
  25.            return DateTime.Now.AddSeconds(-value);  
  26.        }  
  27.   
  28.         public static void Times(this int value, Action<int> action)  
  29.        {  
  30.            for (int i = 0; i < value; i++)  
  31.            {  
  32.                action(i);  
  33.            }  
  34.        }  
  35.   
  36.    }  
   发表时间:2007-07-03  
抄吧抄吧,先是java后是ruby
反正不用微软的破东西
0 请登录后投票
   发表时间:2007-07-03  
吸取别人的长处是好的,可惜ms的平台就是太乱了,部署起来费劲,
尤其是不同版本之间的部署,或者安装了好多MS的软件的时候冲突,头疼。
0 请登录后投票
   发表时间:2007-07-04  
在这里Readonly等人已经对LINQ进行了评价
http://www.iteye.com/topic/76944

语言应该是博采众长的
引用

In terms of the evolution of programming languages, LINQ represents a fusion of a typical OO language (C#) with ideas taken from modern dynamic languages such as Ruby and functional languages such as Lisp. It’s a thoroughly interesting idea and its availability probably will make C# a technical advance on Java, for a time at least. However, whether it actually delivers better (more powerful, more reliable and more maintainable) applications - which is presumably what it's all about at bottom for the companies employing .NET developers - depends on how C# and VB programmers take to such concepts as lambda expressions, expression trees and declarative programming.

http://www.techworld.com/features/index.cfm?FeatureID=2982
0 请登录后投票
   发表时间:2007-07-11  
抄ruby? 你这不是坐井观天么, closure难道是ruby发明的啊?
那ruby的闭包是不是抄袭了Lisp、Smalltalk 和Haskell,甚至perl lua?
0 请登录后投票
   发表时间:2007-07-27  
只能说两点:
(1) 微软有好的技术团队,敢于面对非议!
(2) .net平台的基础设计的很好( CTS 和CLR) 
0 请登录后投票
   发表时间:2007-08-17  
CLR这个平台还是很赞的 他们好像在CLR上面做Dynamic Language Runtime,然后再这个基础上做IronRuby (以前还有IronPython, 不过用的人似乎不多)
0 请登录后投票
   发表时间:2007-09-27  
ray_linn 写道
抄ruby? 你这不是坐井观天么, closure难道是ruby发明的啊?
那ruby的闭包是不是抄袭了Lisp、Smalltalk 和Haskell,甚至perl lua?

0 请登录后投票
   发表时间:2007-10-29  
某些人 喜欢把 "MS抄袭" 放在嘴上.
不是MS是否抄袭XXX 的商业上的成功啊?
0 请登录后投票
   发表时间:2007-10-29  
我反而觉得C# 3.0的static extension的实现方式简单有效。那可不是module,只是一个静态方法。经常我们写测试的时候就希望expect.call这样的API不是用Expect类加call静态方法实现的,而是ExpectCall一个静态方法。
0 请登录后投票
论坛首页 编程语言技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics