using comment above `else` bombs #931

Closed
trailsandtribulations opened this Issue Mar 19, 2013 · 10 comments

Comments

Projects
None yet
4 participants

the following bombs

//-first choice
if abc == 1
  h1 First Choice

//-second choice
else
  h1 Second Choice

if the comment "//-second choice" is removed, it works ok.

with comment in, get error SyntaxError: Unexpected token else

Contributor

vendethiel commented Mar 19, 2013

And if you indent it ?

have not tried. makes sense that it should be in the same indentation
level as the if for which it matches, doesn't it?

On Tue, Mar 19, 2013 at 2:24 PM, Nami-Doc notifications@github.com wrote:

And if you indent it ?


Reply to this email directly or view it on GitHubhttps://github.com/visionmedia/jade/issues/931#issuecomment-15100631
.

Contributor

vendethiel commented Mar 19, 2013

It think the comment generates a DEDENT token, closing the if block, and that's why the else is not expected.
I agree comments could be chomped.

that makes sense, but I think should be chomped is correct.

I like Jade a lot, but it's filled with these gotchya's that make it
difficult to use except for the simplest tasks.

On Tue, Mar 19, 2013 at 8:14 PM, Nami-Doc notifications@github.com wrote:

It think the comment generates a DEDENT token, closing the if block, and
that's why the else is not expected.
I agree comments could be chomped.


Reply to this email directly or view it on GitHubhttps://github.com/visionmedia/jade/issues/931#issuecomment-15113208
.

Owner

ForbesLindesay commented Mar 19, 2013

I agree that we have a lot of gotchas that really need fixing. I think in this case you may just have to indent the second comment though. Jade is very strict about indentation, which makes sense.

is there any way I could help some with these things?

being "strict about indentation", as you said, should have no bearing if
the line is a comment line. the idea that a comment could effect blocking
is just too weird.

for now leaving out the comments (to my chagrin), since the mis-tabbed
comment is actually misleading.

thanks for looking at this

On Tue, Mar 19, 2013 at 9:00 PM, Forbes Lindesay
notifications@github.comwrote:

I agree that we have a lot of gotchas that really need fixing. I think in
this case you may just have to indent the second comment though. Jade is
very strict about indentation, which makes sense.


Reply to this email directly or view it on GitHubhttps://github.com/visionmedia/jade/issues/931#issuecomment-15115458
.

This seems to be a personal coding-style that conflicts with Jade and not an actual bug. Maybe a Jade-compatible coding-standard needs to be written.

What about putting the same comments at the same indentation as h1?

if abc == 1
  //-first choice
  h1 First Choice
else
  //-second choice
  h1 Second Choice

I think the "style" of coding not an arbitrary choice but rather
necessitated by logic and feel.

consider the following example:

// customer late payment
- if( rcd.due_dt < (new Date).formatDt() && rcd.due_amt > 0 )

  // show standard payment request
  div.payment-request
    ...

  // show standard contact me
  ...

// customer has due amount
- else if( rcd.due_amt > 0 )

  // show standard payment notice
  div.payment-notice
    ...

   // give links for account history
   ...

// customer has nothing due
- else
  ...

at the risk of sounding pedantic, I strongly believe that:

saying on top of the block what's going on within the block is both
intuitive and correct. it can be thought of as the block title.

saying within the block what's going on, while perhaps sufficient for
simple cases, is misleading with larger and complex cases.

On Sat, Apr 13, 2013 at 4:37 AM, Joseph Balancio
notifications@github.comwrote:

This seems to be a personal coding-style that conflicts with Jade and not
an actual bug. Maybe a Jade-compatible coding-standard needs to be written.

What about putting the same comments at the same indentation as h1?

if abc == 1
//-first choice
h1 First Choice
else
//-second choice
h1 Second Choice


Reply to this email directly or view it on GitHubhttps://github.com/visionmedia/jade/issues/931#issuecomment-16319055
.

There are different styles of commenting too (another example below). I'm not saying that one is better than another. Whatever works for the developer(s) to best document and maintain the code. However, a specific style of coding shouldn't be forced upon a programming language.

// if late payment then show standard payment request and standard contact me
// else if amount is due then show standard payment notice and links for account history
// else customer has nothing due
if rcd.isPaymentLate()
  include payment-request
  include contact-me
else if rcd.isPaymentDue()
  include payment-notice
  include account-history-links
else
  include cat-picture

agree - different styles for different folks.

but still think that Jade bombing because of a comment above the else
block is just plain wrong.

which I thought was the driving issue

On Sat, Apr 13, 2013 at 1:58 PM, Joseph Balancio
notifications@github.comwrote:

There are different styles of commenting too (another example below). I'm
not saying that one is better than another. Whatever works for the
developer(s) to best document and maintain the code. However, a specific
style of coding shouldn't be forced upon a programming language.

// if late payment then show standard payment request and standard contact me
// else if amount is due then show standard payment notice and links for account history
// else customer has nothing due
if rcd.isPaymentLate()
include payment-request
include contact-me
else if rcd.isPaymentDue()
include payment-notice
include account-history-links
else
include cat-picture


Reply to this email directly or view it on GitHubhttps://github.com/visionmedia/jade/issues/931#issuecomment-16328702
.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment