Your issue is actually a really good example of why comments matter.
- if foo
-# This will do blah
- else
-# This will do bloo
is distinct from
- if foo
- else
Another example is multiline blocks:
- bar = |
baz |
-#
= baz + |
boom |
this means something very different than
- bar = |
baz |
= baz + |
boom |
As for error messages, it's not really possible to get enough contextual
information to determine whether or not someone's doing something they
shouldn't.
- Nathan
Evgeny Bogdanov wrote:
> Now I got explanation, and everything seems to be logical.
> However, initially (maybe because of c, java, ruby and so on) I
> thought that comments(there position in the code) can't influence
> on the execution process, but in reality it can!
> And I didn't understand what was the problem with my code until by
> chance I didn't remove the commented line.
>
> I thought it is only my problem, but none of my partners knows about
> it. Maybe it is worth doing in order to improve haml to pay new users'
> attention
> to this fact, or to give a warning, when the comment seems to be in
> wrong place(like between if-else), or just to delete comments during
> execution
> (I still didn't get the point to treat them as part of the code, if I
> am wrong, could you please give me an example of using comments)
>
> I agree that it is cool to have comment about "else" inside of this
> "else", but one has to make a user aware, that it shouldn't be before
> "else".
>
> I don't think that the problem in haml, but in user perception of
> things he is used to
>
> Regards,
> Evgeny
>
> On Mar 3, 10:54 am, Wincent Colaiuta <[EMAIL PROTECTED]> wrote:
>
>> El 3/3/2008, a las 10:05, neem escribió:
>>
>>
>>
>>
>>> Thank you for the explanation!
>>>
>>> In my opinion, to improve the haml comments should be possible at any
>>> place, anyway they are removed.
>>> When interpretator sees -#, it should remove the line. Probably, I am
>>> mistaking and can't see the problems, that could appear in this case.
>>>
>>> Another problem. When I put the code like this:
>>> - if
>>> -# comment
>>> - else
>>> there is a translation into
>>> if
>>> end
>>> # comment
>>> else (but why I don't receive a notification about error?, can it
>>> happen that block of code begins with "else" without "if" before?)
>>>
>> I know this may seem like a limitation (lack of flexibility as to
>> where you can put your comments) but it's actually a strength of Haml.
>> One of the reasons why Haml markup looks so clean is that it uses
>> indentation to communicate semantics, just like Python does. So the
>> benefit you get is auto-closing scopes and no need to worry about
>> explicitly writing "end" all the time, and the cost is that you have
>> to be disciplined about your use of whitespace. In other words, the
>> rule is "indentation matters"; I think introducing exceptions to the
>> indentation rules would reduce the simplicity and elegance of the
>> rule, because it would become "indentation matters, uh, except for
>> when..."
>>
>> In the example you originally posted you wrote:
>>
>> -if
>> blah
>> -# foo
>> -else
>> blah
>> -end
>>
>> But you've broken the indentation rule right there, so to fix them
>> you'd write:
>>
>> -if
>> blah
>> -# foo
>> -else
>> blah
>> -end
>>
>> Which obviously reduces the visually continuity of the "foo" comment
>> and the part of the code that it applies to, so where should the
>> comment go?
>>
>> -if
>> blah
>> -else
>> -# foo
>> blah
>> -end
>>
>> That's the spot for it, as it respects the indentation rule and its
>> location clearly shows the block of code that it applies to.
>>
>> Cheers,
>> Wincent
>>
> >
>
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Haml" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/haml?hl=en
-~----------~----~----~----~------~----~------~--~---