Loading ...
Sorry, an error occurred while loading the content.

1207Re: [jslint] Function return with and without value does not give any warning

Expand Messages
  • Woomla
    Mar 8, 2010
      --- In jslint_com@yahoogroups.com, Stefan Weiss <weiss@...> wrote:
      > > I think you should program your functions to always return a value,
      > > or never. And don't mix this. That way, you're always forced to think about
      > > and define what you're functions should do an return. Even better, write
      > > a unittest where you define the input and outcome of your function.
      > >
      > > Anyway, a little jslint warning, which I personally would threat as
      > > an error, would be very helpfull here.
      > I don't agree. This would be similar to the "strict warnings" setting in
      > Firefox, which does as you suggest, and is so annoying that everybody I
      > know leaves them turned off. We did have a phase where we tried to
      > conform to the "always (or never) explicitly return a value" idea, but
      > adding "return undefined" at the end of functions quickly became a
      > nuisance. It didn't add any kind of safety, in my experience, because
      > the behavior was exactly the same as before.

      Unfortunately I must agree. And I surely don't want to swim againts the current. If you can circumvent the jslint warning by adding return undefined, then probably it's not a good idea to have the warning in the first place. But if there was a warning, it would still mean that the programmer has to pay attention to his or her function and it can not slip through unforseen. All my functions either have or don't have return values, and a mix for me will indicate an error.

      If only the rest of the world would also program that strict :-) But then it is probably better to make it a typed language. (Which in fact phplint is doing!)

      > If you feel you really need this feature, you could just run your code
      > in Firefox, and turn the strict JavaScript warnings on.

      Of course I can do this. And probably I can do this to get all kind of bad programming and bugs visible. But it is so much easier to use jslint. And also all warnings from third party scripts appear as well. And there will be many, so it will be hard to spot my single
    • Show all 7 messages in this topic