TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Bython: Python with braces. Because Python is awesome, but whitespace is awful

60 点作者 TowerTall大约 1 年前

23 条评论

Kim_Bruning大约 1 年前
The first time I used python I was amazed.<p>I just wrote my code as normal (indented, thank you very much) and could ignore semicolons and curly braces, and the code just ran.<p>I was done in half the time!<p>This seems like a regression by people who are bad at indenting their code. ;-)<p>(see also: <a href="https:&#x2F;&#x2F;pypi.org&#x2F;project&#x2F;goto-statement&#x2F;" rel="nofollow">https:&#x2F;&#x2F;pypi.org&#x2F;project&#x2F;goto-statement&#x2F;</a> )
评论 #39667063 未加载
评论 #39666983 未加载
评论 #39667378 未加载
评论 #39667074 未加载
stefanos82大约 1 年前
I was bitten so many times by un-indented code, thanks to copy &#x2F; paste that took me hours for figure out what was the actual problem.<p>I wish Python had closing...how do we call them, tags(?), clauses?<p>Anyway, here&#x27;s an example of what I mean:<p>Before:<p><pre><code> def IsPalindrome(s) -&gt; bool: for i in range(len(s)): if s[i] != s[len(s)-1-i]: return False return True print(&quot;Is Anna a palindrome?&quot;, IsPalindrome(&#x27;ANNa&#x27;.lower())) </code></pre> after:<p><pre><code> def IsPalindrome(s) -&gt; bool for i in range(len(s)) if s[i] != s[len(s)-1-i] return False endif endfor return True enddef print(&quot;Is Anna a palindrome?&quot;, IsPalindrome(&#x27;ANNa&#x27;.lower()))</code></pre>
评论 #39667379 未加载
评论 #39667271 未加载
评论 #39667679 未加载
评论 #39668799 未加载
aspyct大约 1 年前
What is so wrong about properly indenting your code that you feel it&#x27;s necessary to add {} to make it better?
评论 #39666729 未加载
评论 #39666678 未加载
评论 #39666759 未加载
评论 #39666654 未加载
评论 #39667093 未加载
评论 #39668364 未加载
评论 #39668667 未加载
评论 #39666912 未加载
smokel大约 1 年前
Amazingly, Scala has recently adopted significant whitespace [1], and is moving in the opposite direction.<p>If you can call 2021 recent, that is.<p>[1] <a href="https:&#x2F;&#x2F;docs.scala-lang.org&#x2F;scala3&#x2F;reference&#x2F;other-new-features&#x2F;indentation.html" rel="nofollow">https:&#x2F;&#x2F;docs.scala-lang.org&#x2F;scala3&#x2F;reference&#x2F;other-new-featu...</a>
评论 #39666857 未加载
sergioisidoro大约 1 年前
An interesting note about braces is how US-keyboard centric they are. Typing a braces in many keyboard layouts requires 3 keys presses (or AltGr)<p>Not having braces makes python very easy to teach where the keyboard layouts do not favour those characters accessibility.
评论 #39667885 未加载
finger大约 1 年前
<p><pre><code> if __name__ == &quot;__main__&quot; { print_message(10); } </code></pre> This just looks wrong without parenthesis around the conditional statement.
评论 #39666893 未加载
评论 #39666856 未加载
评论 #39666719 未加载
评论 #39666785 未加载
评论 #39666798 未加载
评论 #39666708 未加载
Einenlum大约 1 年前
I first thought this was trolling, but reading some reactions here and there it&#x27;s probably not.<p>I love how concise and clean Python looks. I would rather see other languages removing brackets.
aitchnyu大约 1 年前
Can 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:<p>``` with lib.html(): with lib.body(): with lib.ul(): for i in items: with lib.li(): lib.add(i) ```
评论 #39669210 未加载
cwales95大约 1 年前
This unironically makes Python seem more cosy to me. It just <i>feels</i> better. My unpopular opinion, anyway.
评论 #39667496 未加载
_ZeD_大约 1 年前
<p><pre><code> $ python3 -c &#x27;from __future__ import braces&#x27; File &quot;&lt;string&gt;&quot;, line 1 SyntaxError: not a chance $</code></pre>
da39a3ee大约 1 年前
People who don&#x27;t like significant whitespace are just people who don&#x27;t use a proper text editor &#x2F; IDE. A lot of them think you have to manually insert the whitespace. It&#x27;s the same with people who complain about parentheses in lisp.
glimshe大约 1 年前
The programming equivalent of &quot;First world problems&quot;
评论 #39667642 未加载
andybak大约 1 年前
Sigh. I miss significant whitespace when I use curly-brace languages. I&#x27;ve got used to it but that&#x27;s mainly Stockholm Syndrome.
twixfel大约 1 年前
If you want braces and hate whitespace, just use another language that has braces and ignores whitespace.
评论 #39669329 未加载
nusl大约 1 年前
I don&#x27;t think I&#x27;ve ever craved braces in Python. I&#x27;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.
omnius42大约 1 年前
If you really want to play with this, this fork is much better than the original: <a href="https:&#x2F;&#x2F;github.com&#x2F;filipefjn&#x2F;bython">https:&#x2F;&#x2F;github.com&#x2F;filipefjn&#x2F;bython</a>
mikewarot大约 1 年前
It almost got there... It should use Begin and End instead. It could then be called PaYthon.<p>Seriously, let&#x27;s just prohibit any of the tab characters(^I,^K,^L) in source code.
评论 #39669826 未加载
评论 #39666762 未加载
评论 #39668797 未加载
signaru大约 1 年前
It need not be braces. Maybe the &#x27;end&#x27; in Ruby, Pascal, Matlab or partially in Basic would look more natural.
rcarmo大约 1 年前
I’d much rather use Hy, to be honest. at least parentheses hark from a more civilized time :)
qgin大约 1 年前
I love this. I don&#x27;t think it will ever catch on, but I love it.
firecraker大约 1 年前
Why do you need this? You can just<p>from __future__ import braces
评论 #39669249 未加载
pestatije大约 1 年前
my humble opinion: this shouldnt be &quot;Bython&quot;, it should be Python 4.0
评论 #39666655 未加载
frumiousirc大约 1 年前
C without the parenthesis.