Re: [jslint] Re: Array construction bug

... Wouldn t it be clearer and more maintainable to create a function for it anyway? var seperator = repeatString( - , len); it doesn t look as clever to use

Message 1 of 21
, Aug 31, 2012

0 Attachment

> If I want to create, say, a separator line of 'len' dashes, I can do
> that really cleanly and easily with:
>
> var separator = Array(len).join('-');
>

Wouldn't it be clearer and more maintainable to create a function for it
anyway?

var seperator = repeatString('-', len);

it doesn't look as "clever" to use a for loop to concatenate, but is there
a noticeable performance loss? Is it easier to read and understand?

> If there's a one-liner that is just as simple, clean, and obvious as
> that, I'll be happy to use it. But please don't tell me I have to dumb
> down my code and use a multi-line function to do something that works
> perfectly well - until I try to get it past JSLint.
>
> --
> Martin Cooper
>
>

[Non-text portions of this message have been removed]

Alexandre Morgaut

... I think that it s more maintainable and more secure to use a dedicated function One going to the code using the Array constructor might expect that the

>
> > If I want to create, say, a separator line of 'len' dashes, I can do
> > that really cleanly and easily with:
> >
> > var separator = Array(len).join('-');
> >
>
> Wouldn't it be clearer and more maintainable to create a function for it
> anyway?
>
> var seperator = repeatString('-', len);
>
> it doesn't look as "clever" to use a for loop to concatenate, but is there
> a noticeable performance loss? Is it easier to read and understand?

I think that it's more maintainable and more secure to use a dedicated function
One going to the code using the Array constructor might expect that the numebr of characters in the string will be len while it will be (len -1). And even if he take care of that it will mean that most of the time the one line will be:

var str = Array(nbChars + 1).join(char);

It will then become ever less obvious to understand what this code is for compared to

var str = repeatString(char, nbChars);

One of the goals of JSLint is to make your code more maintainable by anyone (even you some some few years...)

Martin Cooper

... Right. So I personally find that taking advantage of what the language has to offer helps me do that. If I have to write a function, document it, and write

> --- In jslint_com@yahoogroups.com, Luke Page <luke.a.page@...> wrote:
>>
>> > If I want to create, say, a separator line of 'len' dashes, I can do
>> > that really cleanly and easily with:
>> >
>> > var separator = Array(len).join('-');
>> >
>>
>> Wouldn't it be clearer and more maintainable to create a function for it
>> anyway?
>>
>> var seperator = repeatString('-', len);
>>
>> it doesn't look as "clever" to use a for loop to concatenate, but is there
>> a noticeable performance loss? Is it easier to read and understand?
>
> I think that it's more maintainable and more secure to use a dedicated function
> One going to the code using the Array constructor might expect that the numebr of characters in the string will be len while it will be (len -1). And even if he take care of that it will mean that most of the time the one line will be:
>
> var str = Array(nbChars + 1).join(char);
>
> It will then become ever less obvious to understand what this code is for compared to
>
> var str = repeatString(char, nbChars);
>
> One of the goals of JSLint is to make your code more maintainable by anyone (even you some some few years...)

Right. So I personally find that taking advantage of what the language
has to offer helps me do that. If I have to write a function, document
it, and write unit tests for it, have I really improved the ability to
maintain my code, over using the language the way it was designed?

In my case, I'm writing code for professional JavaScript developers,
not noobs. I want JSLint to help me find bugs, not tell me I have to
dumb down my code for people who don't understand the language. Having
a warning that I can turn off if I want to use a language feature is
fine; providing no way to get past JSLint while using a perfectly
legal language feature is not.

--
Martin Cooper

> ------------------------------------
>
> Yahoo! Groups Links
>
>
>

Tom Worster

... if a separator line is unlikely to be of variable length (which is probably so): var separator = ---------------------------------------- ; looks good to

trying to do things as one-liners is often a sign of trying to be
clever, which is something JSLint tries to discourage.

not a bug, in my view.

IcedNet Development Team

You may not code for noobs , but you will have new hires, and you will document that one-liner or have to explain it, even to professionals... Knowing how to

Message 5 of 21
, Aug 31, 2012

0 Attachment

You may not code for "noobs", but you will have new hires, and you will document that one-liner or have to explain it, even to professionals...
Knowing how to code in js does not necessarily mean that everyone has read "The Good Parts" or any of the exhaustive tomes that actually mention the misbehavior of core javascript...
Clever code is not clever, and that line could mean anything, let alone relying on the moving target that is js...

I see no bug here.

.02 worth

Peace,
Dan

On 2012/08 /31, at 10:07 AM, Martin Cooper wrote:

>
>
> If I want to create, say, a separator line of 'len' dashes, I can do
> that really cleanly and easily with:
>
> var separator = Array(len).join('-');
>
> If there's a one-liner that is just as simple, clean, and obvious as
> that, I'll be happy to use it. But please don't tell me I have to dumb
> down my code and use a multi-line function to do something that works
> perfectly well - until I try to get it past JSLint.
>
> --
> Martin Cooper
>
> > ------------------------------------
> >
> > Yahoo! Groups Links
> >
> >
>
>

[Non-text portions of this message have been removed]

Martin Cooper

On Fri, Aug 31, 2012 at 8:09 AM, IcedNet Development Team ... It s not supposed to be clever . I am only trying to use a feature that exists in the language.

Message 6 of 21
, Aug 31, 2012

0 Attachment

On Fri, Aug 31, 2012 at 8:09 AM, IcedNet Development Team
<dev@...> wrote:

> You may not code for "noobs", but you will have new hires, and you will document that one-liner or have to explain it, even to professionals...
> Knowing how to code in js does not necessarily mean that everyone has read "The Good Parts" or any of the exhaustive tomes that actually mention the misbehavior of core javascript...
> Clever code is not clever, and that line could mean anything, let alone relying on the moving target that is js...

It's not supposed to be "clever". I am only trying to use a feature
that exists in the language. If the feature wasn't intended to be
used, it wouldn't be there. To say that that tiny amount of code
"could mean anything" is absurd.

> I see no bug here.

Setting aside whether people agree or disagree with my particular use
case, the fact is that JSLint provides *no* way for me to take
advantage of this specific feature of the JavaScript language. None.
There is no "off" switch for this. That is a bug.

Please, you assume much Is it creating a new array of length len and joining it to the string literal - ? -- and JSLint is supposed to make code clearer...

Message 7 of 21
, Aug 31, 2012

0 Attachment

Please, you assume much
Is it creating a new array of length 'len' and joining it to the string literal '-' ?

-- and JSLint is supposed to make code clearer...

Not arguing your desire, just restating what Douglas has said time (and time again)...

Good luck.

Peace,
Dan

On 2012/08 /31, at 12:30 PM, Martin Cooper wrote:

> On Fri, Aug 31, 2012 at 8:09 AM, IcedNet Development Team
> <dev@...> wrote:
> > You may not code for "noobs", but you will have new hires, and you will document that one-liner or have to explain it, even to professionals...
> > Knowing how to code in js does not necessarily mean that everyone has read "The Good Parts" or any of the exhaustive tomes that actually mention the misbehavior of core javascript...
> > Clever code is not clever, and that line could mean anything, let alone relying on the moving target that is js...
>
> It's not supposed to be "clever". I am only trying to use a feature
> that exists in the language. If the feature wasn't intended to be
> used, it wouldn't be there. To say that that tiny amount of code
> "could mean anything" is absurd.
>
> > I see no bug here.
>
> Setting aside whether people agree or disagree with my particular use
> case, the fact is that JSLint provides *no* way for me to take
> advantage of this specific feature of the JavaScript language. None.
> There is no "off" switch for this. That is a bug.
>
> --
> Martin Cooper
>
> > .02 worth
> >
> > Peace,
> > Dan
> >
> >
> > On 2012/08 /31, at 10:07 AM, Martin Cooper wrote:
> >
> >>
> >>
> >> If I want to create, say, a separator line of 'len' dashes, I can do
> >> that really cleanly and easily with:
> >>
> >> var separator = Array(len).join('-');
> >>
> >> If there's a one-liner that is just as simple, clean, and obvious as
> >> that, I'll be happy to use it. But please don't tell me I have to dumb
> >> down my code and use a multi-line function to do something that works
> >> perfectly well - until I try to get it past JSLint.
> >>
> >> --
> >> Martin Cooper
> >>
> >> > ------------------------------------
> >> >
> >> > Yahoo! Groups Links
> >> >
> >> >
> >>
> >>
> >
> >
> >
> > [Non-text portions of this message have been removed]
> >
> >
> >
> > ------------------------------------
> >
> > Yahoo! Groups Links
> >
> >
> >
>

[Non-text portions of this message have been removed]

John Hawkinson

One of the problems I have with this discussion is that the cost of having to go read this repeatString() function, however it is implemented, is significant.

Message 8 of 21
, Aug 31, 2012

0 Attachment

One of the problems I have with this discussion is that
the cost of having to go read this repeatString() function,
however it is implemented, is significant. But some analysis
appears to ignore that.

The oneliner proposed is fairly clear to me.
More so than the for loop variants.

But even if they were more clear, I do not think that would justify
the programmer cost of having another function to review, test, and
consider.

But either way, these are reasonable judgements and it seems like yet
another reminder that JSLint is not a JS code quality tool, as much as
it is a style enforcement tool, and for only one person's style in
particular.

And it is the nature of style that it varies wildly and it is rare
indeed for two programmers to see eye-to-eye on all style points.

It saddens me that JSLint, which could be an awesome tool,
instead is just about fights over style. I wish we could rise
above this, but I do not see a path forward.

i just think JSLint isn t for everyone. i had been using it with greater or lesser enthusiasm for years until, after watching the video of douglas talk at

Message 9 of 21
, Sep 1, 2012

0 Attachment

i just think JSLint isn't for everyone.

i had been using it with greater or lesser enthusiasm for years until,
after watching the video of douglas' talk at txjs11 several times, i had a
blinding conversion. finally i saw that it doesn't matter what i think
about code style. the only thing that matters is reducing the chance of
bugs now and in the future while assuming that my code is going to be
inherited by marginally competent programmers(*).

before this conversion, JSLint would sometimes annoy me with its nagging.
the annoyance would manifest something like "but i know what i'm doing" or
"but i don't like that" or "my version is better". now, whenever that
feeling comes upon me i tell myself (sometimes out loud): "it doesn't
matter what you prefer, tom, not even a little bit." and once i calm down
i can usually see the wisdom of JSLint's suggestion.

code is not design and programming is not the act of designing.
programming is a dreadful business. i welcome anything that can improve
the chance that the program will be and will remain correct.

but obviously many programmers don't share my view. and JSLint isn't for
everyone.

If you can switch off the emotional side of your brain, the logic is very hard to refute. There are whole classes of errors you will never see when using JSLint. It improves the odds of success, and in terms of QA and support costs, those odds are measured in dollars.

I could go on about how debilitating opinionated format wars and code style "creative differences" can be, both to a team and the software they produce. Instead, I'll just encourage everyone: If you work as part of a team of any size other than one, rely on this cold, heartless tool to get your JavaScript code-base consistent. It can take all the gnashing of teeth and chest pounding your team can throw at it.

--- In jslint_com@yahoogroups.com, Tom Worster <fsb@...> wrote:
>
> i just think JSLint isn't for everyone.
>
> i had been using it with greater or lesser enthusiasm for years until,
> after watching the video of douglas' talk at txjs11 several times, i had a
> blinding conversion. finally i saw that it doesn't matter what i think
> about code style. the only thing that matters is reducing the chance of
> bugs now and in the future while assuming that my code is going to be
> inherited by marginally competent programmers(*).
>
> before this conversion, JSLint would sometimes annoy me with its nagging.
> the annoyance would manifest something like "but i know what i'm doing" or
> "but i don't like that" or "my version is better". now, whenever that
> feeling comes upon me i tell myself (sometimes out loud): "it doesn't
> matter what you prefer, tom, not even a little bit." and once i calm down
> i can usually see the wisdom of JSLint's suggestion.
>
> code is not design and programming is not the act of designing.
> programming is a dreadful business. i welcome anything that can improve
> the chance that the program will be and will remain correct.
>
> but obviously many programmers don't share my view. and JSLint isn't for
> everyone.
>
> and, btw, i liked one part of douglas' talk so much i transcribed it:
> http://thefsb.wordpress.com/2012/07/10/code-quality/
>
> (*) and when i'm really honest with myself i have to count myself among
> them.
>

Joe Hansche

... I agree with this. I really don t disagree with Crawford, or JSLint... but on SOME things I do. I use it a lot, because you re right: it does find bugs

> **
>
>
> Hey Tom,
>
> That TXJS11 talk was great wasn't it!
> http://vimeo.com/25606006
>
> If you can switch off the emotional side of your brain, the logic is very
> hard to refute. There are whole classes of errors you will never see when
> using JSLint. It improves the odds of success, and in terms of QA and
> support costs, those odds are measured in dollars.
>
> As far as style goes, I also recommend Jeff Atwood's blog post "Death to
> the Space Infidels":
> http://www.codinghorror.com/blog/2009/04/death-to-the-space-infidels.html
>
> I could go on about how debilitating opinionated format wars and code
> style "creative differences" can be, both to a team and the software they
> produce. Instead, I'll just encourage everyone: If you work as part of a
> team of any size other than one, rely on this cold, heartless tool to get
> your JavaScript code-base consistent. It can take all the gnashing of teeth
> and chest pounding your team can throw at it.
>

I agree with this. I really don't disagree with Crawford, or JSLint...
but on SOME things I do. I use it a lot, because you're right: it does
find bugs that other people might mistake or miss. I do all I can to avoid
the JSLint errors that come up in my own files. I will rewrite stuff, move
stuff around, etc, to reduce the number of JSLint errors I see. What sucks
is that not all of my coworkers use JSLint. So when I do (in other
people's files), most of the mistakes are not mine. And being in a
corporate world, I really don't have the luxury of just changing all their
shit around, unfortunately.

And unfortunately, some of the complaints are about things that are so
trivial, I can't really justify (passing a code review) changing everything
about a JS file just because JSLint says it's bad. I might agree with the
a lot of it, but if I want to get my code to production, trust me, I'm not
going to follow JSLint to fix all the other issues in the file (which I
didn't write).

I use JSLint on my own (new) files, because I know that it will end up in
better code. Code that I can manage better, in case bugs are found; and
in case someone else has to touch it, hopefully they are faced with far
fewer issues to deal with.

That said, I don't agree with the *attitude* that Crawford takes on the
*programmers*. I work with a lot of very talented individuals. But the
general consensus is, if you don't write in HIS style, you are a BAD
programmer. I have more colorful words to describe my distaste in that,
but let's just leave it at "I am not moved" by his distrust of the entire
development community. I have my style, he has his. My style to date has
not left me in a bad state, and I still try to follow his "suggestions," as
far as JSLint is concerned.

But for other developers out there, you have to weigh the cost of following
Crawford, vs finding your own style (and please do be sure that it is both
safe and sane -- his rules do have purpose, and you must make sure that
your style takes into account those reasons). Just don't get sucked into
following JSLint only because the tool says you should. If you understand
the reason behind the warning, and you know why you did something some way
that the linter tells you you shouldn't... It's okay. It's okay to
violate JSLint. It's okay to violate Crawford's style.

It's only a style, by the way. It's not a bad style, by any means. It's a
great way to teach uninformed programmers that what they are trying to do
is far and away a bad thing to do -- and the tool will tell you that.

For an experienced programmer, specifically one who knows what the rules
are intended for, it's a little overkill. But then it's your job to decide
if the rules are worth following or not. If you can determine that,
knowing full well what the rule is designed to suggest *against*, yet you
have a reason for it anyway, ... then just ignore that rule. You don't
have to worry about hurting Crawford's feelings for doing so (he'll *never*
feel bad about hurting your feelings).

--- In jslint_com@yahoogroups.com, Tom Worster <fsb@...> wrote:
> >
> > i just think JSLint isn't for everyone.
> >
> > i had been using it with greater or lesser enthusiasm for years until,
> > after watching the video of douglas' talk at txjs11 several times, i had
> a
> > blinding conversion. finally i saw that it doesn't matter what i think
> > about code style. the only thing that matters is reducing the chance of
> > bugs now and in the future while assuming that my code is going to be
> > inherited by marginally competent programmers(*).
> >
> > before this conversion, JSLint would sometimes annoy me with its nagging.
> > the annoyance would manifest something like "but i know what i'm doing"
> or
> > "but i don't like that" or "my version is better". now, whenever that
> > feeling comes upon me i tell myself (sometimes out loud): "it doesn't
> > matter what you prefer, tom, not even a little bit." and once i calm down
> > i can usually see the wisdom of JSLint's suggestion.
> >
> > code is not design and programming is not the act of designing.
> > programming is a dreadful business. i welcome anything that can improve
> > the chance that the program will be and will remain correct.
> >
> > but obviously many programmers don't share my view. and JSLint isn't for
> > everyone.
> >
> > and, btw, i liked one part of douglas' talk so much i transcribed it:
> > http://thefsb.wordpress.com/2012/07/10/code-quality/
> >
> > (*) and when i'm really honest with myself i have to count myself among
> > them.
> >
>
>
>

[Non-text portions of this message have been removed]

Your message has been successfully submitted and would be delivered to recipients shortly.