TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

What if C++ looked more like Python or CoffeeScript?

66 pointsby SupremumLimitabout 11 years ago

21 comments

pwangabout 11 years ago
This is an interesting exercise, but most of the suggestions on the page are just cosmetic, and do not address the fundamental challenge of C++ - perhaps the biggest divergence between Python and C++:<p>A core design principle of C++ is that you do not pay (performance-wise) for what you don&#x27;t use. This leads to all sorts of nasty things like object slicing, law of big 3, template preprocessor hell just to get pseudo-generics.<p>A core design principle of Python is that you should pay the minimum cognitive burden for what you are not using. Don&#x27;t care to customize object dispatch? Then you don&#x27;t need to know about descriptors and __slots__ just to write a simple class.<p>No amount of syntactic cargo culting is going to bridge this gap. The whitespace and lack of semicolons is not why people embrace Python. Just as removing integer types and sensible scoping from C++ won&#x27;t make it Javascript, replacing braces with tabs is not going to make it Python.
评论 #7719233 未加载
评论 #7719413 未加载
Qworgabout 11 years ago
This is the exact opposite of what I want in C++.<p>The use of characters to clearly delineate code sections and scope is a strong benefit of C++ over these other languages. They&#x27;re not a &quot;source of errors&quot; - they allow a competent programmer the opportunity to quickly reason about the structure of the code. If vertical compression is an issue - get a bigger monitor or an IDE that allows for code hiding.<p>It is also far better to have a &quot;oops, I missed a brace&quot; error that your compiler&#x2F;IDE catches, versus a &quot;man, why does my program keep seg faulting unexpectedly&quot; error that takes hours to track down since you missed a single tab somewhere.
评论 #7719264 未加载
评论 #7719372 未加载
评论 #7719351 未加载
评论 #7719269 未加载
claudiusabout 11 years ago
<p><pre><code> $ wc -c a.cpp t.cpp 399 a.cpp 380 t.cpp 779 total $ cat t.cpp #include &lt;iostream&gt; using namespace std; namespace utils { template&lt;typename T&gt; T square(const T&amp; n) { return n * n; } } int main() { int input(0); auto message(&quot;Please enter a positive number&quot;); cout &lt;&lt; message &lt;&lt; &quot;:\n&quot;; cin &gt;&gt; input; if (input&gt;0) { cout &lt;&lt; &quot;Result: &quot; &lt;&lt; utils::square(input) &lt;&lt; &quot;\n&quot;; } else { cout &lt;&lt; message &lt;&lt; &quot;\n&quot;; } return 0; } $ cat a.cpp #include &lt;iostream&gt; using namespace std namespace utils template&lt;typename T&gt; auto square(const T&amp; n) return n * n int main() auto input = 0 auto message = &quot;Please enter a positive number&quot; cout &lt;&lt; message &lt;&lt; &quot;:&quot; &lt;&lt; endl cin &gt;&gt; input if input &gt; 0 cout &lt;&lt; &quot;Result: &quot; &lt;&lt; utils::square(10) &lt;&lt; endl else cout &lt;&lt; message &lt;&lt; endl return 0 </code></pre> I am not entirely convinced that t.cpp has any more or less noise than a.cpp and where exactly there is any sort of gain from this – I had more trouble indenting the second piece of code properly for HN than the first.
评论 #7719762 未加载
flohofwoeabout 11 years ago
This looks neat on first glance and on small code samples, but I&#x27;ve had so many messed up whitespaces after merging branches that in the real world this would be just another way to shoot yourself in the foot. I really like python for scripting up into the 10k lines-of-code area, but for bigger projects (and teams with more then - say - 3 coders) I wouldn&#x27;t even consider a dynamically typed language, let alone a language where intendations and newlines are language constructs.<p>I don&#x27;t really find the example at the end of the article much more readable (even though it &quot;cheats&quot; a bit by using the C++11 auto keyword and range-based for loop), on the contrary, the white space on the left side looks more messy then on the right side to me.<p>C++ code which has a lot of STL containers and complex templates <i>does</i> look ugly though, that&#x27;s why I prefer to either not use this, or hide it under typedefs and decltypes. I also don&#x27;t like the new auto keyword very much, the compiler SHOULD complain when someone on the team changes types around.
keypusherabout 11 years ago
I love Python and it is one of my primary development languages, but I have come to believe meaningful indentation was a bad idea. As Rob Pike said in the recent Go conference keynote: &quot;It is a profound mistake to have your semantics depend on invisible characters&quot;. Braces also make parsing and auto-formatting easier and better. It seems Go struck a good balance with with a newline after statements (no semicolon necessary), and braces for all structures.
评论 #7719197 未加载
mrbrowningabout 11 years ago
&gt; <i>I’m quite fond of languages with minimal syntax.</i><p>Maybe this is the Lisp enthusiast in me, but as someone who does the bulk of their workaday programming in Python I still feel compelled to say that it&#x27;s a perverse worldview that holds up Python as an instance of &quot;minimal syntax.&quot;
评论 #7719245 未加载
sanxiynabout 11 years ago
This doesn&#x27;t seem to address <a href="http://en.wikipedia.org/wiki/Most_vexing_parse" rel="nofollow">http:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Most_vexing_parse</a> at all.<p>On the other hand, if you don&#x27;t care about backward compatibility, I guess completely eliminating constructor syntax in favor of C++11 uniform initialization syntax is a good solution as any. (But maybe curly brace haters won&#x27;t like that solution.)
评论 #7720127 未加载
评论 #7719322 未加载
porgesabout 11 years ago
This looks really error-prone to me.<p>Have you looked at previous attempts, such as SPECS? <a href="http://www.csse.monash.edu.au/~damian/papers/HTML/ModestProposal.html" rel="nofollow">http:&#x2F;&#x2F;www.csse.monash.edu.au&#x2F;~damian&#x2F;papers&#x2F;HTML&#x2F;ModestProp...</a>
评论 #7719235 未加载
评论 #7719256 未加载
minaandrawosabout 11 years ago
How about exploring a modern language like Google GO (Golang)? Go was designed exactly for the purpose of having a performance that could be compared to some extent to powerful languages like C&#x2F;C++ and in the same time maintains a Python like syntax. I have programmed with both languages and I&#x27;d say by the end of the day both languages are powerful tools in your developer&#x27;s toolbox however Go is a very attractive choice when it comes to rapid to develop performant applications
评论 #7719274 未加载
sreanabout 11 years ago
It has not been mentioned in the original post or the comments yet, so here is a working prototype of a similar idea <a href="https://github.com/pfultz2/Pythy" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;pfultz2&#x2F;Pythy</a> (for some specific value of working, you will need Clang)<p>Its birth lies here <i>Having it all: Pythy syntax for C++</i> [1]. It was a nice read. Unfortunately cpp-next seems to be down right now. Let me try to find it in Google&#x27;s cache or internet archive.<p>Here it is <a href="https://web.archive.org/web/20130820172127/http://cpp-next.com/archive/2011/11/having-it-all-pythy-syntax/" rel="nofollow">https:&#x2F;&#x2F;web.archive.org&#x2F;web&#x2F;20130820172127&#x2F;http:&#x2F;&#x2F;cpp-next.c...</a><p>[1] <a href="http://cpp-next.com/archive/2011/11/having-it-all-pythy-syntax/" rel="nofollow">http:&#x2F;&#x2F;cpp-next.com&#x2F;archive&#x2F;2011&#x2F;11&#x2F;having-it-all-pythy-synt...</a>
评论 #7719756 未加载
shurcooLabout 11 years ago
This really reminds me of a similar attempt for Go, called iGo [1]. There are a lot more cases to handle for C++.<p>[1] <a href="https://news.ycombinator.com/item?id=7444459" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=7444459</a>
评论 #7719282 未加载
评论 #7719626 未加载
616cabout 11 years ago
Since no one has said so yet, and I quickly searched the comments, the answer is basically a language called Nimrod.<p>It shows up here a lot, and not many people use it still. Time will tell.
sanxiynabout 11 years ago
This doesn&#x27;t seem to allow single line if or while statements, because parentheses are optional.<p>I like single line if when it is appropriate. (Python allows single line if by using colons.) Apart from my taste, C preprocessor macros can&#x27;t expand to more than a single line, so this seems to prevent macros expanding to contain control structures. Is there an easy fix?
评论 #7719298 未加载
评论 #7719439 未加载
ASneakyFoxabout 11 years ago
Python is easier to type but its harder to read. Ides that help you code faster are a better investment of time than a language that&#x27;s easier to write in notepad. My ide does brackets and indention for me. I never think about them. They&#x27;re just there for my reading pleasure. I like these things its easier to follow the code when reading.
zvrbaabout 11 years ago
If you think that syntax is THE problem that needs to be solved to make C++ less error-prone, you don&#x27;t know shit about C++.
andrewstuartabout 11 years ago
Why can&#x27;t IDEs just hide all the brackets and replace them with sane whitespace structure?
评论 #7719201 未加载
评论 #7719597 未加载
评论 #7719207 未加载
Executorabout 11 years ago
I would support this if you can remove header files. It is hell to manage function prototypes. Let the compiler figure that out with &quot;public&#x2F;private&quot; keywords.
pskocikabout 11 years ago
What if I wanted to take a peek at this article without giving up my email address? If only there was an easy way to stop JavaScript from blocking my page view with that subscribe request …
drivingmenutsabout 11 years ago
If it looked more like Python or CoffeeScript, then it wouldn&#x27;t be C++ anymore.
评论 #7719412 未加载
jbejaabout 11 years ago
Nobody needs that
kcbannerabout 11 years ago
Seems like a step in exactly the wrong direction