logoalt Hacker News

alex_xtoday at 10:29 AM6 repliesview on HN

I wonder why all these easy-to-learn languages use indentation to denote scope, not something like curly braces. Isn't it actually harder to explain?


Replies

Wowfunhappytoday at 1:02 PM

Fifth grade teacher here. Significant whitespace is a major reason I prefer Python for teaching programming.

1. I want kids to indent their code anyway; they may not realize it (or won't admit it), but this makes the code much easier for them to read. Kids will not do this unless they have to.

2. Unbalanced brackets are a major source of mistakes and confusion for my students. Relying purely on indentation resolves this problem—at the real cost of introducing indentation mistakes, but since I want kids to indent their code anyway, this is okay.

By the way, an adjacent recommendation is to configure the editor to indent with tabs instead of spaces (regardless of how you feel about tabs vs spaces in production code). Otherwise, kids will invariably end up with lines indented by 3 or 7 or some other wacky number of spaces. If possible, highlight the tabs in a different color so the kids don't use spaces by accident.

show 2 replies
NooneAtAll3today at 12:50 PM

while everyone already pointed out that this time it's not the case, I want to literally answer the question you asked

"easy-to-learn languages" use indentation because otherwise newbies would not indent at all

I you try teaching programming, you'll find that indentation is one of things students "optimize out" - it is not important to the program, it is opposite of lazy and it's not noticeably harmful on the tiny scale of programs you learn programming from

Indentation discipline only starts to matter when you need to work on the same code for quite some time and code itself takes a lot of space - the "read more then written" situation. And most study paths do not encounter this regime

show 1 reply
jim_lawlesstoday at 10:55 AM

It looks like MiniScript uses the keyword "end" followed by another keyword to denote the end of a specific type of block.

From the Quick Reference guide here:

https://miniscript.org/files/MiniScript-QuickRef.pdf

"Indentation doesn't matter (except for readability)."

layer8today at 12:09 PM

The language (MicroScript) doesn’t require indentation, it’s only used for readability, like in BASIC, FORTRAN, PASCAL, and similar languages. Blocks are delimited by key words (“end if” etc.).

graemeptoday at 10:49 AM

I think indentation is more intuitive. Even people using languages that use braces or similar usually use indentation to make code readable. If doing that you end up explaining both ideas (use braces and indent).

show 2 replies
echoangletoday at 10:35 AM

It makes sure the thing you use to judge scope (indentation) matches the think the computer uses.

show 1 reply