coffeedoc / codo

CoffeeScript API documentation generator. It's like YARD but for CoffeeScript!
Other
625 stars 92 forks source link

@propertys in class are bad style and produce unexpected behavior #231

Closed AtiX closed 8 years ago

AtiX commented 8 years ago

see coffeescript cookbook

class Person
  # @property [Array<String>] the nicknames
  nicknames: []

nicknames can be accessed by using @nicknames in every instance, but will have the same value for all instances(!). This style of defining properties only works for primitives.

My suggestions:

  1. Change README example because it will produce unexpected behavior
  2. It's suggested (coffeescript cookbook) to define instance variables in the constructor instead. Thus parse @property in constructor as well.
inossidabile commented 8 years ago

I'm not sure I understand. Is your claim that we promote a bad style of coding in our Readme?

AtiX commented 8 years ago

Yes, "bad style" because code will break in unexpected ways when using the style used in the README. I've written a small example here.

Second point: @property is only recognized using the style above - so only when done wrong. A better alternative is to declare properties in constructor, so it would be good to parse the @property tag in the constructor.

inossidabile commented 8 years ago

I think you don't really understand prototype inheritance and how Coffee interacts with it. The property will not have the same value across all instances. It will prototypically override the value on the level of class object. You are missing it with static invocation badly. So this is no way a bad practice to start with.

But anyway. There was almost 2 years since I last time answered something similar before so let me be a bit more explicit. What you suggest us is to drop reasonable, straightforward and very well specified syntax and replace it with what? Reading the mind of a developer? Do you realize how many ways there exist to define a property? So even if we forget the wrong syntax claim and go straight to rational core of adding more possible syntaxes... Oops, we can't. Sorry.