TopLanguage

分享经验是最大的复用!

TopLanguage的公告
除非特别声明,本站采用Creative Commons License许可。注明作者、出处,非商业。

这是一个小组(团体)博客,如果你觉得你的经验值得分享,任何时候欢迎加入我们,请先移步我们的讨论小组TopLanguage

订阅这个博客

  • XML聚合
  • 订阅到鲜果
  • 订阅到Google
  • 订阅到抓虾
  • 订阅到BlogLines
  • 订阅到Yahoo
  • 订阅到GouGou
  • 订阅到飞鸽
  • 订阅到Rojo
  • 订阅到newsgator
  • 订阅到netvibes
最近评论
文章分类
    收藏
      相册
      其他
      TopLanguage人物志
      duguguiyu|Venus神庙
      Googol
      刘未鹏(pongba)|C++的罗浮宫
      刘江|图灵
      孟岩(Mike Meng)
      徐宥(You XU)|4G Spaces&Web 2.3
      杨文博(solrex)|Solrex Shuffling
      莫华枫(longshanksmo)
      袁泳(g9)|负暄琐话
      存档
      软件项目交易
      订阅我的博客
      XML聚合  FeedSky
      订阅到鲜果
      订阅到Google
      订阅到抓虾
      订阅到BlogLines
      订阅到Yahoo
      订阅到GouGou
      订阅到飞鸽
      订阅到Rojo
      订阅到newsgator
      订阅到netvibes

      原创 API考古学之“C风格的Java API”收藏

      新一篇: GP技术的展望——道生一,一生二 | 旧一篇: 类型系统的四个维度

      By pongba

       

       

      #从fishbowl上看到的,非常幽默:

      Occasionally in Java, you come across an API that makes you sit up and go “What were they thinking?” Take, for example, the code to list all the threads in the current ThreadGroup. Rather than having the obvious method: i.e. one that returns a list (or array) of threads, the signature looks like this:

      int enumerate(Thread[] list)

      You pass an empty array to the method, which will be filled with Thread objects. The method then returns the number of threads it placed in the array. If the array is not long enough to accept all the threads, the overflow will be silently discarded.

      To initialise the array, you must rely on ThreadGroup#activeCount, which only returns an approximation of the number of threads that enumerate might return.

      If you’re looking to avoid memory leaks in a non-garbage-collected environment, then it makes perfect sense for an API to push responsibility for memory management back up its caller, and to gracefully handle whichever buffer-size it’s given to fill. When you’ve got pervasive GC, it just looks (and is) clumsy.

      So the obvious answer to “What were they thinking?”, of course, is “They were thinking like C programmers”.

      Which in turn leads one to suspect that this particular API has been around since before Java was called Java.

      The Fishbowl: Charles Miller's Weblog

      #另一方面,这个例子完美体现了GC语言的优势。

      发表于 @ 2007年12月26日 19:05:00|评论(loading...)|编辑

      新一篇: GP技术的展望——道生一,一生二 | 旧一篇: 类型系统的四个维度

      评论:没有评论。

      发表评论  


      登录
      Csdn Blog version 3.1a
      Copyright © TopLanguage