7 ms·
Python with Braces
- bluehex 13y agoI love it. If this could transparently convert to and from normal Python I could see wrapping it in an editor plugin so that the braces could be visible to those of us who prefer them, while the output could remain traditional Python for interoperability with an established codebase.
- plorkyeran 13y agoIt would be simpler to just make an editor which displays a { after any end-of-line colon and lines with } before each deindent, without actually adding them to the file.
- chmullig 13y agoThis is bad, and you should feel bad.
- orisomething 13y agoHey, I will just say, I'm not the one who behind this project. This project belong to two people I familiar with. Maybe I can arrange more "official" response from them about this project. Though, I want to say, This discussion just prove one of the probable core concept of this project. You should have the ability to choose the syntax that is right for you. The language stays (pretty much) the same. P.S. I don't program in Python at all. The last time I've programmed in Python was a few years ago, when 2.4 was fresh (and I would still claim I didn't even really programmed then). I think indention base syntax has its advantages and disadvantages. But it's not pure good.
- tsm 13y agoMaybe I'm being too harsh, but I feel like anyone who considers this a good idea isn't a sufficiently-Pythonic thinker to be writing Python anyway. Python isn't just a language--it's a culture, and one of that culture's core principles is that there should be one way to do it.
- Pacabel 13y agoOne of the best things about Python is that there's comparatively little "culture", at least compared to Perl, Ruby or JavaScript. The culture/community that does exist is more oriented toward helping people achieve what they want to or need to get done, rather than smugly regurgitating alleged "best practices" (Ruby and JavaScript) or absurdity (Perl). Yes, there are the PEPs, but they're more about providing useful guidelines that can likely offer some benefit if followed, rather than dictating the "best" way of doing something. Avoiding the typical Python approaches may raise some eyebrows or cause some confusion, but basically never the visceral lashing that one would be likely to receive within the Ruby community, for example.
- skywhopper 13y agoWow, now I really don't want to learn Python. (Psst, you have the most popular programming language. You can take off your persecution complex.)
- billforsternz 13y agoI don't understand; You hate that Python is all about helping people get things done ? That repels you ?
- skywhopper 13y agoWhat repels me is the defensiveness and the apparent need to criticize other language communities. I'm not interested in joining a cult.
- Pacabel 13y agoLike many other people, I use Python, Ruby, JavaScript, Java, and several other languages on an ongoing basis. We don't really care about "communities" or "cultures" and whatnot. We just have work that we need to get done using those programming languages. This isn't about "defending the Python culture" or "attacking the Ruby community" or any crap like that. Having dealt with so many different communities over the years, the Python community is by far the best to deal with, from a practical standpoint. Whenever I've had a Python-related question, the members of that community have done their best to help me out with achieving what I want to do. This is very different from the typical response from the Ruby or JavaScript communities, where they'll consistently tell you that what you're doing is "wrong" or against their "best practices" of the hour. That's not the kind of "help" that we're looking for. Get all emotional about this if you want. That's your right. But the rest of us have pragmatic, real-world concerns. The Python community does an excellent delivering us with useful help when we need it. Certain other communities do not. Those are just the facts.
- tasty_freeze 13y agoI can't believe someone skilled enough to do this has actually not realized why it is a colossally bad idea. Having a working compiler is just one tiny aspect of the problem. Unless there is a transparent way to interoperate with the rest of the Python ecosystem (libraries, tools), it is dead in the water. Even then, this seems like a lot of work to overcome a non-problem, akin to developing a C++11 compiler which uses "begin" and "end" instead of braces because of some emotional attachment to Pascal. Really, if you are a programmer and the only thing stopping you from using Python to solve some problem is its indentation rules, you should stop and reevaluate your priorities.
- vezzy-fnord 13y agoEven then, this seems like a lot of work to overcome a non-problem, akin to developing a C++11 compiler which uses "begin" and "end" instead of braces because of some emotional attachment to Pascal. The thing is, it's actually trivial to do that using the C++ preprocessor. In fact, Steve Bourne wrote the Bourne shell exactly in this fashion, with the following C substitution macros (based on Algol-68): #define STRING char * #define IF if( #define THEN ){ #define ELSE } else { #define FI ;} #define WHILE while ( #define DO ({ #define OD ;} #define INT int #define BEGIN { #define END } Source: Expert C Programming: Deep C Secrets, p. 13. Peter Van der Linden. 1994. (this isn't to deny that Python with Braces is a rather frivolous idea)
- shuzchen 13y agoI'm mostly surprised that they went into the actual parser/compiler and modified that. If I were crazy enough to do this, I'd probably just write a pythonb-to-python compiler.
- deleted 13y ago[deleted]
- deleted 13y ago[deleted]
- ollysb 13y agoThe examples kind of feel like an introductory page to coffeescript, in reverse. I think it does a great job of showing why meaningful indentation is cleaner. Now I want it for ruby :)
- lucidguppy 13y agofrom __future__ import braces File "<stdin>", line 1 SyntaxError: not a chance
- Apreche 13y agoWhat if you want to make a dictionary? you = {'are': 'screwed'}
- lutusp 13y agoSurely they accommodate this syntax in the scheme. The whole project would collapse if they didn't.
- bluehex 13y agoI don't see the ambiguity. Braces in expression position -> dict constructor. JavaScript is a fine example of how this is not a problem.
- chewxy 13y agoActually, it is. It is very easy to confuse an object literal and a block in Javascript. In fact, in the book I am writing[0], I dedicate an entire chapter to using this ambiguity to write arsehole code. Here's another example[1] [0] https://leanpub.com/underhandedjavascript https://leanpub.com/underhandedjavascript or its alternate title: https://leanpub.com/jsinterviewquestions https://leanpub.com/jsinterviewquestions [1] Slide 21 (1-index): https://speakerdeck.com/chewxy/underhanded-javascript-how-to-be-a-complete-arsehole-with-bad-javascript https://speakerdeck.com/chewxy/underhanded-javascript-how-to... EDIT: For those of you who do not want to click through my self promotional links, try this in your browser: {}[0] == true // false {}[1] == true // true !{}[0] == true // true !{}[1] == true // true
- lowboy 13y agoDo you have any non-contrived examples of confusing an object literal and a block? Because as soon as you see this { identifier: You know it's an object literal and not a block.
- deleted 13y ago[deleted]
- bcj 13y ago
- rcruzeiro 13y agoOk, I don't want to be mean but, why would some do all this work to workaround one of the coolest Python features?
- bitsoda 13y agoWhy do some people feel like meaningful indentation is a deal-breaker with Python? It makes for readable code even in curly brace languages like JS, Java, and C. In fact, I found the first curly brace example with the odd indentation jarring. Being able to quickly scan a block of code and get a sense for what belongs to which block is incredibly valuable.
- pmorici 13y agoIn my experience the people that complain about it most are those who just like to slop things together and not bother with even the most cursory attention to detail. For people with that attitude having to worry about details like white space no matter how trivial "gets in their way".
- iMark 13y agoI've had 20 years of dealing with C style parentheses and I've learned to parse it visually at a glance. I can't do the same with languages which use significant white space instead. I imagine I could train myself to do so, but there is a cost involved.
- nedbat 13y agoI suspect if you were presented with a piece of code where the indentation and the braces disagreed, you would believe the indentation. Yes, it's easy to parse at a glance if it is correct, and the indentation agrees with it. If it doesn't, good luck seeing the error. This is one of the good things about significant indentation: the human and the computer are reading the same signals.
- jnazario 13y agowhile i concur, there is one shining example where this is a problem: fixing someone else's code where a bug has been introduced due to mistaken indentation. last week i fixed a bug where a mistake in indentation (maybe a cut and paste in a refactor?) caused something to be done once but not the correct number of times (once for every iteration). took a few minutes to figure out where to look, but it took a few minutes more to figure out what was intended and what the bug ultimately was (the disconnect between what you meant and what you did). while this is a small 2 line example, for larger code blocks this is a serious problem. i'm not advocating for braces, but they have a helping hand in spotting these sorts of bugs. that said i often dislike it when people dismiss python just on the whitespace complaint alone.
- dhon_ 13y agoI don't understand, this is already available with >>> from __future__ import braces
- tghw 13y agoSyntaxError: not a chance
- jey 13y agoIsn't this a bit early? It's not even March yet.
- Demiurge 13y agoPlease, no :(
- stuartk 13y agoI literally shuddered when I read this. Significant whitespace to me is one of the fundamental parts of Python that if messed with, makes it not Python. Perhaps this will make it slightly easier for people coming from PHP, Javascript or one of the many languages that do use curly braces, but significant whitespace is a selling point, not a hinderance IMO.
- jnbiche 13y agoYou know, when I first started programming and got attached to Python, I longed for significant whitespace in other languages, such as Javascript (which drove me to Coffeescript) and C (which just drove me nuts). I avoided languages like Java and C# because they had so much syntactic "noise"., because they were statically typed, and because they were clearly inferior languages. And Lisp...well, I shuddered at the thought of learning Lisp because of all those parentheses. Now, however, I don't give a damn about braces. I use Java if the job calls for it, and I've developed quite an appreciation for C#. I enjoy playing around with Lisp and recognize that it shares a lot of fundamental features with Python. I have a strong appreciation for C's power and control (but use it only under very certain circumstances and with great trepidation). Python is still my go-to language because of its incredible ecosystem, but I no longer insist on using it for everything. I use the right tool for the job. I dropped Coffeescript in favor of pure Javascript, which I've come to appreciate as not a bad language, as long as you're aware of the traps. For larger jobs, I usually seriously consider using a statically-typed language, because I know I'll either have to religiously write unit tests, or suffer a world of pain (and even then odd bugs will happen that otherwise would not have). Point is, I suspect that very often, those people that insist on bringing the syntax from one language to another are either early in their career, or they're focused on the wrong thing. If the presence or absence of braces is the feature of a language that bothers you most, then you want want to reevaluate your priorities. (that said, if this project was just a fun way to explore Python's internals and lexers/parsers, please carry on!).
- jfoster 13y agoWhy shouldn't the syntax matter? If a syntax results in more mental overhead, it seems sensible to avoid it if possible. What seems up for debate is what actually results in more mental overhead, and what just takes some getting used to.
- jakejake 13y agoI almost did a spit-take when I read this. I actually do very little work in Python so I have no personal opinion on the subject, but I have a few close friends that are hard-core python programmers. I imagine the nerd rage that braces would incite. I'm gonna send this link to them now, sit back and watch chaos ensue. Bwa ha ha (rubs hands together)!
- lukasm 13y agoI would actually use it with iPython
- smaudet 13y agoWoot! Ditto. :)
- lukabratos 13y agoThis makes no sense at all.
- lutusp 13y agoScore: +1 : the idea of braces in Python -1 : The fact that the project addresses an out-of-date Python version (2.7 instead of 3+). Result: 0
- taternuts 13y agoI use 3.x myself but if I were to do something like this I'd probably target 2.x/the majority as well, at least at first.
- d0m 13y agoJust playing Devil's advocate, but one very good use of {} is for real anonymous functions. I.e. map([1,2,3], lambda (x) { print x return x * 2 }) That's one of the limiting reason why we can't have that in Python right now
- orisomething 13y agoI think I need to add a disclaimer: - I'm not the one who behind this project - actually, I'm a not a real programmer (I'm a graphic designer who also code) - the people behind this project can be found in Github. At least I can say about one of the who is a close friend, that he codes in Python about 8 years as a profession - I'll ask him to open a user and add his thoughts to this discussion (if he doesn't have yet)
- workhere-io 13y agoHuh? Lack of braces is one of the things I like about Python. Additionally, on many non-English keyboards braces are somewhat hard to write (e.g., on a Danish Mac keyboard it's a three-letter combo: Alt + shift + 8). Not having to write braces is nice. One of the examples on the page says "indentation doesn't matter". But the thing is, it does matter - even if there are braces. Correct indentation means that your code is more readable. Python (the normal version without braces) enforces correct indentation, which is brilliant.
- umurgdk 13y agoWHY????? Do you have endless empty time?
- Fizzadar 13y agoDepressing to think anyone on this earth finds curly braces an improvement to Python. I always prefer languages without, curly braces are ugly!
- matthewmacleod 13y agoKudos for having the motivation to pull this together, I guess! I must admit, I don't get why anybody would be interested in using this. Even the headline snippet is an example of "what not to do." Python's significant whitespace incurs the small overhead of requiring attention to detail when copying and pasting code - that's pretty much the only downside, and it seems strange to add a feature while boils down to "allow slopping indentation practice at the cost of extra syntax." I thoroughly believe syntactic noise is an enemy of productivity. Good editors will help to some extent, but I find the process of reading (say) CoffeeScript much more pleasant than JavaScript. Each to their own, of course.
- batguano 13y agoWhat really bugs me is when spaces and tabs get mixed together in the same file. That's godawful.
- levlandau 13y agoi'm sorry, don't mean to be harsh at all, but this is just a bad idea.
- gte910h 13y agoThis should be implemented as a editor plugin...with the actual files having none
- freefrancisco 13y agoWorst idea ever! It's like "upgrading" humans to walk on 4 legs.
- iliaznk 13y agoBlasphemy!
- freefrancisco 13y ago{ {because;} {language;} {improves;} {when;} {you add;} {curly braces;} {and;} {semicolons;} {to it;} }
- elnate 13y agoCan we have this with explicit typing? (Not even a joke)
- rbanffy 13y agoIf someone really loves curly braces so much, there is no shortage of languages that offer them. This is like making a Lisp dialect without parentheses or a Smalltalk without messages. Fair disclosure: I used a language called Actor that was pretty much Smalltalk without messages. I mean, there were messages. They just looked like function calls with the receiver as first parameter.
- dang 5y agoWe changed the URL to the archive.org version because the original domain now points to malware.