8 ms·
Bython: Python with braces. Because Python is awesome, but whitespace is awful
- pestatije 3y agomy humble opinion: this shouldnt be "Bython", it should be Python 4.0
- visarga 3y agocould be optional so Python would be easier to pick up by people migrating from curly braces
- andybak 3y agoSigh. I miss significant whitespace when I use curly-brace languages. I've got used to it but that's mainly Stockholm Syndrome.
- aspyct 3y agoWhat is so wrong about properly indenting your code that you feel it's necessary to add {} to make it better?
- happymellon 3y agoYou could always ask Apple. Braces are explicit, whitespace implicit. https://embeddedgurus.com/barr-code/2014/03/apples-gotofail-ssl-security-bug-was-easily-preventable/ https://embeddedgurus.com/barr-code/2014/03/apples-gotofail-...
- arunix 3y agoAnd of course, "Explicit is better than implicit" https://en.wikipedia.org/wiki/Zen_of_Python#Principles https://en.wikipedia.org/wiki/Zen_of_Python#Principles
- JohnKemeny 3y agoIn Python, whitespace is explicit, so actually, the bug you just posted hadn't happened if they used Python. Indeed, in your link, the braces are implicit too.
- gkbrk 3y agoBeing able to copy-paste code with every editor and not ending up with broken code is a real time saver.
- lozenge 3y agoOnly if the use of a stupid editor is saving you time.
- spirit557 3y agoSo if this became popular you'd have some camps using it and some not. Wouldn't that be ironicly more annoying than the problem it's solving?
- bsza 3y agoNo, since the conversion is trivial in both directions and a plugin could do it automatically.
- andybak 3y agoWhy have I never had a problem copy/pasting Python? What are y'all doing??
- cjfd 3y agoThere is nothing wrong with properly indenting code. The lack of {} makes python very ugly when things no longer fit on one line. Because Python has an opinion about whitespace there are certain ways one can break a line an other ways one cannot. The result looks very ugly. Maybe the old way of using a backslash was not the worst, but linters nowadays don't like that anymore. Also having : also does not make things look better. Python must be one of the most ugly looking languages out there.
- giancarlostoro 3y ago> when things no longer fit on one line That sounds like a PEP-8 violation ;) All your lines should be under 79 characters. Might look ugly to some but to others it looks fine.
- housecarpenter 3y agoYou might be already aware of this, but besides using the backslash, the other way you can allow an expression to span multiple lines in Python is to enclose it in brackets. I find this to be pretty unobtrusive. Often your line break will already be within a pair of brackets anyway.
- xigoi 3y agoBlack can usually reformat code pretty well.
- Netcob 3y agoI don't get it either. I mostly use C#, but I somehow manage to properly indent it anyway. Whenever I use python, I don't have any issues with indentation. To me this discussion always sounds a bit like people complaining they can't find any brown underwear.
- datavirtue 3y agoThe "properly" part.
- bernds74 3y agoProperly indenting code is fine. Now try modifying that code, like removing an if statement inside somewhat nested code and trying to ensure that everything still has the same meaning as before. With Python, you can never be sure you did it right.
- rlpb 3y agoI don't see why not. Simple visual inspection confirms if it does what you expect, unlike languages that use braces.
- qgin 3y agoBecause everyone (and all their editors) on every project have to handle indentation identically or as soon as someone makes an edit, things won't run.
- throwawa14223 3y agoFor my ability to read and assess source code significant white space kills me.
- mikewarot 3y agoIt almost got there... It should use Begin and End instead. It could then be called PaYthon. Seriously, let's just prohibit any of the tab characters(^I,^K,^L) in source code.
- vsnf 3y agoSurely you don’t mean tab and vertical tab, so you must be talking about tab and… space? How would a language with no spaces look like? How do you separate tokens?
- nusl 3y agoTabs are different to normal spaces though, so it would use 2 or 4 spaces instead of a single tab.
- SAI_Peregrinus 3y agoASCII Unit Separator, 0x1F. Obviously. Or more seriously like any of the existing slightly more sane languages that don't need spaces, like the Lambda Calculus.
- xXx_uwu_xXx 3y agoNo, the tab is a wonderful invention and should be celebrated.
- mikewarot 3y agoYes, Tabs are great for filling out the same forms in Triplicate every day, if you're into old timey workflows.
- timbit42 3y agoAlgol 60 and Pascal had 'BEGIN ... END' to handle multiple statements in a block, but Ada and Wirth's successors, Modula-2 and Oberon, removed them except to denote where code begins in a PROCEDURE. It is much cleaner. Poorly contrived example in Oberon: IF n > 1 THEN n := n * n; RETURN 0 ELSE RETURN 1 END
- finger 3y agoif __name__ == "__main__" { print_message(10); } This just looks wrong without parenthesis around the conditional statement.
- dvh 3y agoIn pascal you can call function that has no arguments without parentheses: writeln; if x = 5 then writeln;
- kova12 3y agoIt does, doesn't it? I wish there was some sort of compat layer which would allow to natively use python libraries in Javascript
- dartos 3y agohttps://github.com/extremeheat/JSPyBridge https://github.com/extremeheat/JSPyBridge Happy hacking!
- ComputerGuru 3y agoWelcome to rust!
- apetrovic 3y agoHuh? Rust, Go, Swift and probably many more languages does the same.
- paulcole 3y agoI’ve got a side project called Parenthon that I’m going to release soon. Let me know if you want in on the beta!
- ufo 3y agoThe purpose of parenthesis is too let the language know when the condition ends, and the statement begins. In a language with mandatory curly braces, the brace does that job already.
- cwales95 3y agoThis unironically makes Python seem more cosy to me. It just feels better. My unpopular opinion, anyway.
- pseufaux 3y agoNot sure it's really that unpopular. I personally find braces harder to read. Perhaps they are more explicit, but it just adds clutter. Compared to C and Java (even well formatted) I'd rather read someone else's Python code any day.
- smokel 3y agoAmazingly, Scala has recently adopted significant whitespace [1], and is moving in the opposite direction. If you can call 2021 recent, that is. [1] https://docs.scala-lang.org/scala3/reference/other-new-features/indentation.html https://docs.scala-lang.org/scala3/reference/other-new-featu...
- nine_k 3y agoIDK; Haskell normally uses significant whitespace, but also can use braces instead, so you can write any snippet linearly. Won't fly with Python's "one way to do it" principle though.
- firecraker 3y agoWhy do you need this? You can just from __future__ import braces
- Kim_Bruning 3y agoI fell for it so others don't have to ;-) >>> from __future__ import braces File "<stdin>", line 1 SyntaxError: not a chance
- frumiousirc 3y agoC without the parenthesis.
- deleted 3y ago[deleted]
- Kim_Bruning 3y agoThe first time I used python I was amazed. I just wrote my code as normal (indented, thank you very much) and could ignore semicolons and curly braces, and the code just ran. I was done in half the time! This seems like a regression by people who are bad at indenting their code. ;-) (see also: https://pypi.org/project/goto-statement/ https://pypi.org/project/goto-statement/ )
- bsza 3y agoWhy do I need to be good at indenting when it can be 100% automated assuming the language has braces? I’m a programmer, not a typesetter from 1520.
- NotMichaelBay 3y agoIndenting is not hard, and programmers should be good at it, provided they care about clean code. I like that Python forces indentation rules because it means I'll never have to read code that has confusing/improper indentation. ESLint has an indent rule to enable it for JavaScript.
- manishsharan 3y agoCopying and Pasting code around is really cumbersome with indenting. Refactoring code is harder. Or maybe it's just me.
- otabdeveloper4 3y agoa) All sorts of shitty code and text formatters will ignore or clobber whitespace. b) When reformatting code like for a in x: f(a) if something: g() you're liable to make a typo and commit a grave logic error.
- jerpint 3y agoWhy would curly braces stop you from making the same logic error?
- nusl 3y agoI don't think I've ever craved braces in Python. I've had a few bugs due to indentation but that happens with braced languages too. If this is your preference just careful that Bython is supported into the future that you expect to use it.
- twixfel 3y agoIf you want braces and hate whitespace, just use another language that has braces and ignores whitespace.
- stefanos82 3y agoI was bitten so many times by un-indented code, thanks to copy / paste that took me hours for figure out what was the actual problem. I wish Python had closing...how do we call them, tags(?), clauses? Anyway, here's an example of what I mean: Before: def IsPalindrome(s) -> bool: for i in range(len(s)): if s[i] != s[len(s)-1-i]: return False return True print("Is Anna a palindrome?", IsPalindrome('ANNa'.lower())) after: def IsPalindrome(s) -> bool for i in range(len(s)) if s[i] != s[len(s)-1-i] return False endif endfor return True enddef print("Is Anna a palindrome?", IsPalindrome('ANNa'.lower()))
- zexbha 3y agoI like these end clauses but they can get cumbersome in heavily nested control structures. Ruby, I'm looking at you.
- jerpint 3y agoSome editors display permanent indentation lines which help visually resolve the indentation
- Chris2048 3y agoI prefer this idea, but instead of a shell-style ending unique to every scoped structure, maybe just a ";" character?: def IsPalindrome(s) -> bool for i in range(len(s)) if s[i] != s[len(s)-1-i] return False; ; return True; I'd also be inclined to skip it for 'def' as well, since they tend not be be as nested.
- jwineinger 3y agowhy not braces then?
- timbit42 3y agoThey either don't line up vertically, or take extra vertical space.
- Einenlum 3y agoI first thought this was trolling, but reading some reactions here and there it's probably not. I love how concise and clean Python looks. I would rather see other languages removing brackets.
- glimshe 3y agoThe programming equivalent of "First world problems"
- Chris2048 3y agoLike almost literally everything else on HN? Including complaining about it..
- sergioisidoro 3y agoAn interesting note about braces is how US-keyboard centric they are. Typing a braces in many keyboard layouts requires 3 keys presses (or AltGr) Not having braces makes python very easy to teach where the keyboard layouts do not favour those characters accessibility.
- bobim 3y agoYes, but lists, dicts and comments still requires reaching altgr nevertheless.
- sergioisidoro 3y agoTrue. But I would say their use is one order of magnitude less than a block delimiter.
- _ZeD_ 3y ago$ python3 -c 'from __future__ import braces' File "<string>", line 1 SyntaxError: not a chance $
- signaru 3y agoIt need not be braces. Maybe the 'end' in Ruby, Pascal, Matlab or partially in Basic would look more natural.
- da39a3ee 3y agoPeople who don't like significant whitespace are just people who don't use a proper text editor / IDE. A lot of them think you have to manually insert the whitespace. It's the same with people who complain about parentheses in lisp.
- qgin 3y agoI love this. I don't think it will ever catch on, but I love it.
- aitchnyu 3y agoCan we also have multi line lambdas? It will make loops in trees of components (html, UI etc) easier. Generating html in Python will look much better than: ``` with lib.html(): with lib.body(): with lib.ul(): for i in items: with lib.li(): lib.add(i) ```
- Kim_Bruning 3y agoThat lib looks very useful in and of itself! Are you thinking of a particular one?
- aitchnyu 3y agoThat was pseudocode. There are tons of libraries like https://pypi.org/project/dominate/ https://pypi.org/project/dominate/
- rcarmo 3y agoI’d much rather use Hy, to be honest. at least parentheses hark from a more civilized time :)
- omnius42 3y agoIf you really want to play with this, this fork is much better than the original: https://github.com/filipefjn/bython https://github.com/filipefjn/bython