D-etractions A real world programmers view on D

Jacob Carlborg doob at me.com
Wed Sep 5 23:47:20 PDT 2012


On 2012-09-05 20:43, Adam D. Ruppe wrote:

> In Javascript for instance, you don't need to use functions at all and
> can just write code that will run at the very top of the file.
>
>
> Sometimes with D, I use a little helper program that adds some phobos
> imports and a void main(){} wrapper to the input, thus getting this same
> effect.
>
>
> I don't like it in anything but short programs though... main() rox.

In Ruby you can also but executable code in class declarations. It's 
heavily used in Ruby on Rails' ActiveRecord implementation:

class Post
   has_many :comments
end

class Comment
   belongs_to :post
end

"belongs_to" and "has_many" are plain class methods. When this is 
possible you rarely need user defined attributes/annotations and similar 
features.

-- 
/Jacob Carlborg


More information about the Digitalmars-d mailing list