Suggestion for Crystal

Hi, recently I remembered a feature can be better for Crystal.

It’s simple, but add like Ruby a way to comment a code in multiple line.
To be honest, comment every each line with the # character can be a bit annoying sometimes.

This was brought up before via Add Block Comment Syntax by will · Pull Request #1401 · crystal-lang/crystal · GitHub, but was rejected. Granted that was 8 years ago, but I still agree with the reasoning.

related: FAQ · crystal-lang/crystal Wiki · GitHub

Hmm okay. Thanks for the explanation

I mostly use the Kate editor for the KDE desktop.
I never knew (never tried to know) how to do this, but a quick search for Kate revealed
all you have to do is block out the section of code (for Crystal) and do a Crtl+d. :clap:

Man, I wish I had known this before.
How many man-years have I wasted doing all those !*$&#^ single line hashes manually. :smile:

Please put this in the Getting Started tutorial.

I think that’s pretty common in editors meant for programming, but it’s different in every editor. Like in Emacs (what I use all the time), you select a region then M-x comment-region.

I actually wouldn’t mind some block comments, though I wouldn’t use them often. I find them most useful when I need to either put a very large comment block in (like here, or when I need to block out a bunch of code. The latter I can do pretty quickly with M-x comment-region and uncomment-region, but I think I’m just used to Common Lisp where I can do #| and |#, which are reader macros iirc :stuck_out_tongue:

Long comments are especially painful if I need to realign markdown within the comment itself, or other lines. Well, “painful” in that it’s just a mild annoyance.

Ruby has

=begin 
...
...
=end

to insert block comments, which I like.

I use block comments usually at the beginning of a file to describe its contents and usage, and at the start of specific methods for the same purposes.

You should depend on the editor feature to make you happy.

I use Ruby almost ten years, but i never use block comment.

To each his|her own.
That’s why Matz put in so many options in the language, so the individual can be happy!

M-x comment-region

Isn’t M-; bound to comment-dwim per default? Can both comment and uncomment.

PHP has both /* comment */ block comments and // comment line comments (and, at least until recently also # comment), but it seems that the consensus on a lot of projects is that /** comment */ is used for doc comments and // comment for inline (aka real) comments. So we have block comments, but don’t really use them for that…

To be frank, it annoys my muscle memory more that strings can’t be single quote delimited.

Actually I kinda like only having one comment type, pretty much every language I’ve been using have had multiple, and it’s often a bit messy to look at.

4 Likes

Today I learned! :D I’ll have to play with this today.