Code Indentation

Well, although this might be strange question, but here it goes as my first topic.

Why NVGT includes and/or engine uses code indentation while it is not required?

Explanations:

  1. Yes, NVGT engineside code seems logic but it is not required though. I wonder why many of the programmers used indentation.
  2. NVGT Include Scripts however, no need to use indentation as far as I can think of. Indentations such as tabs and spaces aren't even required to use, and they even make the programmer having to remember where, how, or how many tabs they have to insert, as well as adding extra texts which they shouldn't be, even if indentations do not take much size.

Every time I contribute to NVGT Include scripts, I have to remember the number of tabs to insert, oh accidentally forgot to insert the number of tabs required for a block, etc.

So, this is logic for programming languages like Python because it requires it, and C style languages as well as HTML, JS, PHP etc are not required.

Thanks!

Hi there,
There are a lot of reasons to indent code, from making it easier on the eyes of sighted programmers to being able to use awesome NVDA add-ons like indent nav.
If you want a text editor that can auto-indent for you (you press tab once and it'll put a tab on every next line until you delete it), try Notepad 2, from https://www.flos-freeware.ch/notepad2.html

Well, thanks for explanations. For me, it is no problem with indentations. I only just asked to know why indentation is used in an unrequired language.

For anyone who interested, Notepad++ is a good alternative application in addition to Notepad2.
There is also an Add-On for NVDA that optimizes accessibility with Notepad++ and improved autocompletion more accessible.

Thanks!

Haha so I think that the indent nav add on was a bit undersold here. This thing lets you browse your code like a tree view and is the *main* reason I got into indentation for myself. To be able to use a couple of button presses to enumerate all classes, then all functions in all classes, then all major parts of the logic flow for each function all because the code is indented, I can't go back. Seeing unindented code is now genuinely hard for me to work with because I can't hold in NVDA+alt and press up and down arrow to navigate between text only on my indentation level. Or in other words, especially with a text editor that handles it for me, I find the extra -1 pain of dealing with indentation to be utterly worth the +10 of being able to browse my code hierarchically instead of pressing ctrl+f and trying to remember my function names or holding down the up arrow for 10 seconds to scoot passed a particularly large block of code.

Nobody suggests that you do the indents manually though. As for indentation management, here is a suggestion as to how to make it easy. Once you have a text editor that can do it for you, say you want to make an if statement. I always type: if () {. Then I press enter, and press tab. Then I press enter twice causing the text editor to create 2 new indented lines, then press backspace and } to unindent the last line by 1 level and close my statement. Now I have the properly indented skeleton of an if statement that I'll go up and fill out. The blank line in the statement is already indented because of the previous actions, and my text editor will do the rest, so now every time I press enter within that statement, all further lines will also be indented.

The entire workflow might take a bit to get into and hey, news flash I coded stw without it for years before finally cracking and learning indentation and being so utterly glad I did, so it's not the end of the world if you choose not to learn it. I stand by what I and others have said though, if you choose to learn it and use the tools that exist to help you and that make it worth it, you are very unlikely to regret the decision. A year before I switched to indentation a friend knowingly laughed at me and said "I'm not worried man, I already know you'll switch to indentation some day and won't look back." A year later we were laughing about how he was right.

1 Like

I wonder, why do you use things like if () {?
In particular, why the brace in the same line than the if statement? Isn't that rather anoying cuz you don't surely know its there? I've always done if ()
{
I like the idea of the work flow though and might try that.

Basically it comes down to avoiding extra arrow presses and indent tones in NVDA, also making sure that NVDA announces the braces.

As for extra arrow presses, I've generally found it to be true that unless I'm carefully analyzing a piece of code, therefor reading the entire line all the way to the end, I don't tend to care whether a brace exists. I tend to be spamming the arrows to navigate to a specific bit of code much more often than I find myself being like "wait, is this line part of the above if statement?" In fact I find myself needing to care where braces are so rarely that I don't mind the extra pressing of up arrow to verify it the few times that I actually do.

As for indent beeps, this almost voids the first point anyway. If you turn on line indentation reporting in NVDA's document formatting settings, now NVDA will just beep at you whenever you enter a code block and will beep at a lower pitch when you exit it. Thus now I know whether the previous line's if statement contains a left brace because if NVDA beeps into a codeblock that lasts more than 1 line, there must be one there.

Finally, if you are like me and you rather your NVDA punctuation setting to be able to be set to some instead of most because hearing left paren right paren quote quote drives you crazy, you can switch the announcement in NVDA for just braces. You go into the Punctuation/symbol pronunciation settings from the NVDA menu, go to the left brace and right brace characters, and you can set them to be reported even in the some punctuation level. Therefor if you read an entire if statement, you are sure to know when it ends with a left brace.

TLDR I just personally find that there are enough solutions to figuring out or not caring whether a line contains a brace to avoid adding a bunch of extra arrow key presses to my coding sessions in order to emphasize such a thing.

I indent because I can't follow code any other way. When it's flat all the way through, I don't even want to read it. Also, if I ever want to collaborate on projects outside the blind community, it's essential. I went through a phase when I didn't bother with it. I felt like it wasted time and energy worrying about such things. But now I wouldn't even conceive of coding flatly.

Put it this way. People who have had some vision and lost it will get what I'm about to say. You know how all along, you knew logically that a cane would be helpful and you should use one, but you just... didn't? then, at some point, something happened and you came to the realization that this would be the time. Remember the people in your life who told you that you should be using one, but you just kind of blew them off? This is that. No one's gonna make you do it, you either will or won't.

1 Like

Thank you dude. You have been so incredible helpful once again. That is indeed a great thing to do and will make my life easyer. A huge thanks!

Very much had the same and agree! Also a good comparison.

Well, thanks for the explanation.

Next, how about padded operators?
if(i>a.length()-1) VS if (i > a.length() - 1)

Lastly, since indentation is a recommended option, could you please recommend which indentation method should be used, tab or space? This also means for HTML, CSS, and C style languages like JavaScript.

Thanks! I'll try to get to the new level of using indentations.

Also please provide me astyle command to process all nvgt scripts under all subfolders and trees, this does not work

astyle --recursive *.nvgt

Hi there.

You're looking for:

astyle --project --recursive *.nvgt

HTH!

Well thanks!

However, this is not for subdirectories. Only 1 level of directory can be used with this.

For example, I had:

  • Includes/
    • Test/
      • test.nvgt
    • Test2/
      • Test2s1/
        • Test2.nvgt
      • Test2.nvgt
    • Include.nvgt
  • Main.nvgt

Anyway, for anyone looking for the way like that, here is a bash one I found just a minute ago at the time of writing:

for /R  %%f in (*.nvgt) do astyle --project=.astylerc --suffix=none "%%f"

Thanks!

wo, I can't live without indentation but, indent nav is mad, If I knew about it before I might have saved so, soooo much time, thtis is amazing
but yes short of it is it makes it easy to remember where you are in code, also use vscode, nvgt has no addon for it but it takes care of indentation automatically and you likely won't care about it ever again, it also takes care of things like braces etc, which makes the chance of having an unproperly closed brace very slim

There is an extension to do a similar thing as Indent Nav in the marketplace. I can't recall its name; though, I think the developer of Indent Nav links to it on their page.

So, in general it is like it is recommended to indent code.

Well, thanks each of your replies. I'm also trying to get into this indentation, and some of my projects have also been formatted with code indents using Astyle command line tool. It won't be easy to change to use indentation as I've been using non indentations for years, but I believe learning and practice will get use to it in a madder of time.

Happy coding!

:slightly_smiling_face:

1 Like

Hello.

So this is an update of me using indents for a week.

First of all, I get comfortable using it in cituations where I forgot function names. Though this is 0 problem on my created projects because I remember function names, but it is started problem when I tested other created projects with 0 indentation. I can now smoothly navigate around the functions with the Indent Nav NVDA Add-on on my projects, decreasing the need for remembering the function names contained in a script.

As I look into other created projects with no indentation, I have to navigate a long list of code to get the function I want to modify, and having the Notepad++ editor to search from the search dialog starting with void, string, etc if indentation isn't used. The reason is because they are other created projects, not mine, so I don't know what functions are there.

Now with indentation, I can just move to the line where 1 tab is, and then use the alt+NumPad2/NumPad8 to jump around the functions in a class smoothly.

So, this means that I'm being more comfortable with indentation day by day.

Thank you everybody!

3 Likes

I do it because it's very useful. Same for padded operators.

When I'm reading code, I turn on indent reporting via tones and it's very easy for me to identify what's a part of the same block that way for example. (Indent Nav doesn't work for me for some weird reason.) Padded operators are useful because it makes it easier to identify what's what when navigating by word. If you don't do this, some symbols will be merged into the prior word (like - for example) because, in English, - is both a word-continuation character as well as padded to indicate a pause. NVDA, however, doesn't know this, so it merges it into the prior word. Same thing for grave accents.