Shop OBEX P1 Docs P2 Docs Learn Events
Writing code is an art form — Parallax Forums

Writing code is an art form

Especially when it's this colorful. JetBrains just released the CLion 2016.3 EAP (that's their way of saying "beta") which includes "semantic highlighting". That means CLion now renders the following code block in one of two ways, depending on your theme settings:

Baseline
#pragma once

#include <PropWare/filesystem/filereader.h>
#include <PropWare/filesystem/fat/fatfile.h>

namespace PropWare {

class FatFileReader : virtual public FatFile, virtual public FileReader {
    public:
        FatFileReader (FatFS &fs, const char name[], BlockStorage::Buffer *buffer = NULL, const Printer &logger = pwOut)
                : File(fs, name, buffer, logger),
                  FatFile(fs, name, buffer, logger),
                  FileReader(fs, name, buffer, logger) {
        }

        PropWare::ErrorCode open () {
            PropWare::ErrorCode err;
            uint16_t            fileEntryOffset = 0;

            // Attempt to find the file
            if ((err = this->find(this->get_name(), &fileEntryOffset)))
                // Find returned an error; ensure it was EOC...
                return FatFS::EOC_END == err ? FatFile::FILENAME_NOT_FOUND : err;

            // `name` was found successfully
            check_errors(this->open_existing_file(fileEntryOffset));
            this->m_open = true;
            return NO_ERROR;
        }

        PropWare::ErrorCode safe_get_char (char &c) {
            PropWare::ErrorCode err;

            if (this->m_open) {
                check_errors(this->load_sector_under_ptr());

                // Get the character
                const uint16_t bufferOffset = (uint16_t) (this->m_ptr % this->m_driver->get_sector_size());
                c = this->m_buf->buf[bufferOffset];

                // Finally done. Increment the pointer
                ++(this->m_ptr);

                return NO_ERROR;
            } else {
                return FILE_NOT_OPEN;
            }
        }
};

}

Light theme
default.png

Dark theme
darcula.png

You'll notice that variables in a function scope each have their own unique color assigned to them. The variables "fs", "name", "buffer", and "logger" are each given their own unique syntax coloring in the constructor. This makes it even easier to spot their usage throughout the function. The same goes for the variables "c", "err", and "bufferOffset" in the safe_get_char function.

I imagine there are number of folks here that might think this is just too much color, and that it is distracting. I think I like it though!
1034 x 928 - 149K
1029 x 922 - 139K

Comments

  • They just came out with a new Pycharm. I'll have to grab a copy and see if they went 'color crazy' with it too. It does help things to jump to your attention once you get used to it (like most new things).
  • I was quite stunned to see that the IDEA 2016.3 EAP does not include semantic highlighting. We'll see if it's something that is backported to the whole IntelliJ platform or if it remains a part of CLion only.
  • DavidZemon wrote: »
    I was quite stunned to see that the IDEA 2016.3 EAP does not include semantic highlighting. We'll see if it's something that is backported to the whole IntelliJ platform or if it remains a part of CLion only.

    JetBrains already responded to my question regarding this actually. Anastasia says:

    https://blog.jetbrains.com/clion/2016/09/clion-opens-2016-3-eap/#comment-30724
    Semantic highlighting is language specific feature, so each team implements it individually. There is some platform code that is already there. But now each product needs to adopt it, when the team has time and resources. Most likely IntelliJ IDEA team will do, but a bit later.
  • ercoerco Posts: 20,256
    I agree code can be a beautiful thing. :)

    http://forums.parallax.com/discussion/165006/bs2-haiku
  • erco wrote: »
    I agree code can be a beautiful thing. :)

    http://forums.parallax.com/discussion/165006/bs2-haiku

    Yes, that thread is quite inspiring :D I'm truly impressed.
  • ElectrodudeElectrodude Posts: 1,657
    edited 2016-09-09 15:05
    I'm not sure that I like it. I couldn't figure out why the syntax highlighting looked inconsistent to my eyes until I read your description explaining that each variable gets its own color. This is only going to be an excuse to give variables bad names, since who needs good names if you can just use the colors? Also, it's buggy, in that two different variables with the same name and type "PropWare::ErrorCode err;" in different scopes are nevertheless the same color.

    And, until an IDE comes around that has a Vi-style interface, I'll never be able to use an IDE again. The editing speed gain that editors like Vim and Kakoune give, with the concept of keystrokes as a text editing language, is just too significant to make the niceties of other editors that don't have these capabilities remotely worth it.
  • I'm not sure that I like it. I couldn't figure out why the syntax highlighting looked inconsistent to my eyes until I read your description explaining that each variable gets its own color. This is only going to be an excuse to give variables bad names, since who needs good names if you can just use the colors? Also, it's buggy, in that two different variables with the same name and type "PropWare::ErrorCode err;" in different scopes are nevertheless the same color.

    I consider that a feature
    And, until an IDE comes around that has a Vi-style interface, I'll never be able to use an IDE again. The editing speed gain that editors like Vim and Kakoune give, with the concept of keystrokes as a text editing language, is just too significant to make the niceties of other editors that don't have these capabilities remotely worth it.

    Have you seen JetBrain's IdeaVim? Heater would appreciate that it's also opensource https://plugins.jetbrains.com/plugin/164
    https://github.com/JetBrains/ideavim
  • Heater.Heater. Posts: 21,230
    Someone mention my name?

    Perhaps we have had this discussion before, but, as far as I can tell, this JetBrains thing is closed source. I don't see any point in having an open source vi/vim mode for it.

    It's really not going to help me when I ssh into some server and want to hack stuff.

    Meanwhile, the open source MS Visual Studio Code IDE has a vim extension.

    Get that, I'm using an MS product. And even liking it. That's a first. :)


  • Heater. wrote: »
    Someone mention my name?

    Perhaps we have had this discussion before, but, as far as I can tell, this JetBrains thing is closed source. I don't see any point in having an open source vi/vim mode for it.

    We have, but this is the Internet, and the Internet is for por... repeating yourself.

    The C/C++ parts of CLion are closed source, but the platform is open, including numerous language agnostic plugins (IdeaVim, Git, Subversion, etc), as well as the Java and Python plugins.
    Heater. wrote: »
    It's really not going to help me when I ssh into some server and want to hack stuff.

    Depends what language you want to use for hacking said stuff. I know PyCharm lets you edit remote files directly in the IDE, without having to execute a SFTP/SCP command before/after to keep them in sync. Every time you hit CTRL + S or let the IDE autosave, it does the sync for you. Then you get all the features of an IDE with quick turnaround of remote editing. I would bet (but haven't confirmed) that it's also available in their HTML/CSS/JavaScript IDE called WebStorm.
    Heater. wrote: »
    Meanwhile, the open source MS Visual Studio Code IDE has a vim extension.

    Get that, I'm using an MS product. And even liking it. That's a first. :)

    That whole MS VS Code thing is pretty cool... I'll give you that :)
  • Heater.Heater. Posts: 21,230
    Yeah but, I just login to our remote servers and use vim.

    If it's actual code changes I want to do then that gets developed and tested locally. It ends up on our server via git. Using github or bit bucket.

    Now, I don't mind whatever tool one uses to develop code. The only requirement is that the resulting code can be worked on by others, built and deployed, without any requirement for closed source tools.



Sign In or Register to comment.