سؤال

I watched with great interest the Mojang "Mojam" for Humble Bundle (link might not be valid for a long time), and throughout the video, I saw some great things on how these guys use their code.

One of these things was that one of the developer use ascii art comments in his code to better navigate around.

This gives something like this:

/////////////////////////////////////////////
//      ___  ___       ___   _   __   _    //
//     /   |/   |     /   | | | |  \ | |   //
//    / /|   /| |    / /| | | | |   \| |   //
//   / / |__/ | |   / / | | | | | |\   |   //
//  / /       | |  / /  | | | | | | \  |   //
// /_/        |_| /_/   |_| |_| |_|  \_|   //
//                                         //
/////////////////////////////////////////////
int main()
{
    // do some stuff
    return 0;
}

This may look bad right there, but associated with editors like Sublime, it becomes powerful, because the "zoomed out" view that Sublime exposes lets you read that text and navigate in your code like a breeze.

Now, there are plenty of cool ascii art text generators out there. But none of these (at least those I looked at) generate C++/C compliant text.

Meaning: I have to manually add the comment slashes (//) all around to make it go along in the code.

Do you guys use this trick?
If yes, do you have a tool to generate these "comments" around the text?

هل كانت مفيدة؟

المحلول

Yes I use to add those kinds of "nav" cues. Specially in communication parts which has many similar parts but handle i.e. different message types.

I work on a Mac so here goes my setup.

Previously I used a dashboard widget http://memention.com/figlet/

But my latest thing is to create a Service with Automator and install figlet with homebrew. Then in the Service I have this one-liner (also clicked "Output replaces selected text")

/usr/local/bin/figlet -f smslant -w 132

Now in any App I can have figlets just by right-clicking some text.

My preferred font is smslant

Then I usually just add /* and */ after.

Edit

Well, I just updated my Service to add that C comment

( echo "/*" ; /usr/local/bin/figlet -f smslant -w 132 ; echo " */" )

نصائح أخرى

Recently, when I was searching something in my .php file with list of routes for a site, I've decided to make such big ASCII comments. And now, I use them (not in all source files, but for example in long config files), and these comments really help to navigate.

Here is how it looks in my Sublime Minimap:

enter image description here

So far, I didn't automate the process of creating such comments. I use online ASCII creator from this site. I use font "basic"

UPD: Linux users of Sublime Text can try this raw but working plugin: https://github.com/maslennikov/asciicomments

NO. I don't use such things and would find such things worse than useless. Screen = bandwidth. Wasting space like this decreases code readability.

            ______
||\   ||   /      \
|| \  ||   |      |
||  \ ||   |      |
||   \||   \______/

:-)

If you're using SublimeText, I suggest to try ASCII Decorator. It's easy to install it, it doesn't require anything else than Sublime and it works on every OS. Plus, it has a lot of nice fonts!

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top