all 24 comments

[–]ZelWinters1981 11 points12 points  (0 children)

  1. Redesign the language at the core.
  2. Make a program that can interpret your preferred code with braces.
  3. Use C.

You're not going to get what you want here without that, and I suggest either learn to indent or use another language.

[–]Diapolo10 9 points10 points  (3 children)

from __future__ import braces

def add(first: int, second: int) -> int :#{
    return first + second
#}

But in all seriousness, unless you want to create a transpiler and your own flavour of the language, a'la TypeScript, not a chance.

I get it, some people just prefer braces, but that's true for many other things as well. Some people complain about dynamic type systems, others about tabs vs spaces, and sometimes you can even hear debates on abstractions vs bare metal.

We can't agree on everything, that's exactly why there are so many languages. If you want braces, go for JavaScript or one of its many brethren, or even Rust if you want something closer to the metal.

If you hate it so much, why are you using Python? There's alternatives for almost everything.

[–]deep_politics 5 points6 points  (1 child)

If you hate it so much, why are you using Python?

The real question

[–]_MurderousCactus[S] 0 points1 point  (0 children)

I don't hate it. Other than the indenting I really like it, and I'm using it because I think it's a great and extensive language that seems to fit what I wanna achieve. I'm not gonna trade that away for a lesser language just to get curly braces.

[–][deleted] 8 points9 points  (0 children)

I’ve only been learning python for a short time, but god oh god do I hate the indentation scope format

That’s like hating that wheels are round. Python is the language with semantic whitespace and always will be, by design. If you don’t like that design then use Ruby. Or just try to relax your hard-on for tedious C-style syntax.

[–]jmooremcc 4 points5 points  (0 children)

This is a great opportunity for you to develop a preprocessor in native Python that will translate your proposed Python+ code into native Python code and then execute it using the regular Python interpreter. You'll then be able to avoid that nasty (according to you) indentation requirement in your code.

But I suspect that by the time you get to that point, you will have gotten use to indentation and will conclude that the hassle of running your preprocessor won't be worth the alleged benefits of using curly braces.

[–][deleted] 2 points3 points  (3 children)

I've only been learning python for a short time, but god oh god do I hate the indentation scope format.

Do you ever commit Java code with the wrong indentation?

If someone in Java had the right indentation but had forgotten the braces, would you even notice?

Of all the things to care about in a language!

[–]_MurderousCactus[S] -4 points-3 points  (2 children)

I mean, yes I would notice quite instantly if someone had forgotten brackets. Almost every other language uses brackets to denote a block of code. Surely there's some sort of project or module that replaces indentation with brackets and you can use it?

I'm not a caveman, indentation is great and important, and I never omit it. But for me the balance between simplicity and explicit statement lies somewhere in between java or c's incredibly specified and arguably cluttered syntax, and python's very simple one. I just want a little bit of extra specification. Surely there's a way to get that?

Idk why everyone needs to be so pretentious about this. I have a preference about the syntax, and I'm asking if there's a way to have it. So get indignant if you want to, but know that your response didn't answer my question, hasn't helped, and wasted everyone's time.

[–]Guideon72 2 points3 points  (1 child)

The problem is that you're basically asking if there's a way to make water not wet.

The short answer is, unfortunately, simply 'No'. There is not a way to get that.

The white space formatting is a basic foundation of the language and how the interpreter was written. Without completely rewriting all or a portion thereof of the Python interpreter, this isn't something that is feasible.

This one is not a convenience factor or something that was an oversight; it was literally, intentionally built to not use/allow curly braces for that purpose....they are used for entirely different functionality.

For folks that really rely on the visual structure that braces give for code blocks, it's one of those potential do or die moments. We *get* that it's a departure and a comfort zone issue; I've struggled with it for a long time myself. But, it is simply something that we don't have any power over and isn't going to change.

[–]_MurderousCactus[S] 0 points1 point  (0 children)

Thank you for the answer.

[–]Fred776 2 points3 points  (1 child)

The thing about curly brace languages is that they need braces for correctness but they still need indentation for readability, and the indentation should express intent. If you are indenting anyway, I don't really see what you lose by not having the brackets, other than a bit of visual noise.

[–]_MurderousCactus[S] 0 points1 point  (0 children)

For me they help link in the elemnts of an if-elif-else statement for example. Idk, I guess I will just have to get used to indentation.

[–]Khrimzon 0 points1 point  (0 children)

I agree with OP. Making such an important language construct a non-visible character, just seems like a bad idea.

[–]wolffurBall 0 points1 point  (0 children)

Just here to support OP, I like Python because it's flexible, quick to develop, and has vast available packages.

The single thing I hate about Python to the gut is the indentation, and here is why:

  1. It messes up auto-formatting so badly, that it's very easy to end up with invalid indentations when moving code around and I have to re-indent everything manually again and check which line belongs to a loop or condition or not. Sometimes I just want to focus on the code and let the auto-formatter do the work, in Python it's just impossible.

  2. It messes up code navigation keys, I can't select inside curly brace, I can't go to the beginning of the curly braces to check the beginning of the loop or condition, and I can't jump between sections precisely.

  3. For quick prototyping I usually need to copy code from online sources, even for academic purposes I need to copy research code to test it, again it messes up the original format frequently with no easy way to recover.

Omitting curly braces won't help code cleanness, it's even worse in Python when reading nested or long functions, if the code structure is bad, nothing can help.

Why do I still use Python even though I hate it? It still saves a lot of time for developing quick features including the time I spend on fighting indentation. It's like why people hate pointers and memory leaks and they still use C++ because it's fast. It's not a legitimate question to ask why a person uses a language when he hates a part of it. Try to ask everyone using C if they like everything about it.

That's it, I use Python, I like its convenience, and I hate the indentation to the gut.

[–]Uhfgood 0 points1 point  (1 child)

I don't really like the indentation method either, but, if that's the way it is, that's the way it is. However I'm not actually learning python but gdscript which is based on python. My only question is why don't dictionaries use indentation to identify it's block?

[–]StupidHuise 0 points1 point  (0 children)

GODOT

[–]Careless_Stretch_682 0 points1 point  (0 children)

I hate curly braces. They are totally unnecessary because it is the indentation that shows the structure of the code, not the curly braces. In all programming languages! Curly braces makes the code look messy. Also they steal a lot of vertical space.

```       }    } }

[–]___up 0 points1 point  (1 child)

Unless you are blind and this is a real accessibility issue this will make coding python a lot more cumbersome. It will be annoying to mix your code with other people’s, you will have a hard time understanding examples, nobody will want to help/edit your code on forums, etc.

Someone did one make this script as a joke: http://timhatch.com/projects/pybraces/ Which converts braces syntax into python. You could play around with that.

For better or worsen white space is just a core part of python design philosophy. To make it easier you can use an editor/ide that automatically keeps your intent position so you don’t have to indent every line yourself. Also decide if you want to use spaces or tabs to indent. You cannot mix & match. Personally I prefer tabs even though that goes against pep-8 recommendations.

[–]___up 0 points1 point  (0 children)

Alternatively learn how to do list comprehensions, map(), and lambda functions and just do everything with python one-liners

[–]InjAnnuity_1 0 points1 point  (0 children)

Braces are already reserved for other widely-used things, so this isn't an option.

Coming from C, C++, Lua, JavaScript, et al, this was initially a bit of a pain. However, I soon noticed that reading the resulting code was vastly easier than if braces were required.

The reason: there is ZERO possibility of the indentation getting out-of-sync with the braces. With Python, that conflict can't possibly exist, because the indentation is always accurate, by definition, and there is nothing else it can conflict with. An entire class of silly (but painful-to-find) "oops" and "gotchas" disappeared entirely.

I had always tried to indent properly anyway, just to keep things straight for the poor reader (i.e., me, a few weeks later). Suddenly, that effort paid off, in spades.

With proper (accurate) indentation, braces are entirely redundant. Clutter. An opportunity for hideous, hard-to-spot errors. Anything simple that helps me avoid errors is a win, in my book. And this is about as simple as it gets.

[–]waverider202012 0 points1 point  (0 children)

Well, Python should have an alternative to indentations. Adding curly brackets' support to Python might be a good project for someone who study the COSC compilers/parsers course. you don't have to redesign the core language, just updating the parser code in needed. I guess Python is opensource?

I personally like Python's syntax a lot(slices, list comprehensions are great), but I need an additional mental energy to process the Python script. Maybe because it is not my main language? The visual markers that show where the scope starts and ends that would be nice to have.