kikito / middleclass

Object-orientation for Lua
https://github.com/kikito/middleclass
MIT License
1.77k stars 190 forks source link

alternative syntax to define a class and its methods. #15

Closed gutenye closed 12 years ago

gutenye commented 12 years ago
Foo = class("Foo", {
  static = {
     create = function(self)
        return "create"
     end
  },

  initialize = function(self, name)
    self.name = name
  end,

  echo = function(self)
    print(self.name)
   end
})

-- with inheritance
Bar = class("Bar", Foo, { 
   ...
})

The advanage is put class definition into a block which is more clean and better look.

kikito commented 12 years ago

Hi Guten,

Thanks for taking the time to organize and send me this pull request.

Unfortunately, I don't agree with your assertion; I don't find it more "clean" or "better look". The current syntax is a bit longer, but in contrast, it does't require an explicit "self" or commas after each method declaration.

The main issue is, however, that the syntax you propose is not a complete "alternative". It forces the method definitions to be one after the other in the same file. You can't define a method only if a condition is true. Or define a class in one file and then add more stuff to it in a different file - you must use the "regular" syntax to do that.

Please don't take this personally, but I will not accept this pull request for those reasons. By all means, feel free to use your fork if it suits your needs.

Regards,

Enrique