Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!eternal-september.org!feeder.eternal-september.org!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed3a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python.': 0.02; 'broken': 0.04; 'syntax': 0.04; 'configure': 0.05; 'subject:Python': 0.06; 'extent': 0.07; 'parser': 0.07; 'suppose': 0.07; 'transform': 0.07; 'git': 0.09; 'performs': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; "wouldn't": 0.14; "(we'll": 0.16; '*any*': 0.16; 'blocks': 0.16; 'braces': 0.16; 'braces,': 0.16; 'delimit': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'symbols': 0.16; 'syntactic': 0.16; 'syntax,': 0.16; 'tab': 0.16; 'proprietary': 0.16; 'ignore': 0.16; 'wrote:': 0.18; 'bit': 0.19; 'commit': 0.19; 'later': 0.20; 'work,': 0.20; 'preferred': 0.22; 'cc:addr:python.org': 0.22; "shouldn't": 0.24; "haven't": 0.24; 'question': 0.24; 'cc:2**0': 0.24; 'sort': 0.25; 'source': 0.25; 'define': 0.26; 'task': 0.26; 'this:': 0.26; '(for': 0.26; 'header :In-Reply-To:1': 0.27; 'on,': 0.29; '[1]': 0.29; "doesn't": 0.30; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; 'code': 0.31; 'easier': 0.31; 'everywhere': 0.31; 'indentation': 0.31; 'file': 0.32; 'probably': 0.32; 'another': 0.32; 'entirely': 0.33; 'actual': 0.34; 'could': 0.34; 'problem': 0.35; 'subject: (': 0.35; 'display': 0.35; 'something': 0.35; 'editor': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'that!': 0.36; 'changing': 0.37; 'example,': 0.37; 'subject:New': 0.37; 'two': 0.37; 'version,': 0.38; 'pm,': 0.38; 'little': 0.38; 'anything': 0.39; 'aside': 0.39; 'sure': 0.39; 'ensure': 0.60; 'dave': 0.60; 'truly': 0.60; 'matter': 0.61; 'simply': 0.61; "you'll": 0.62; 'more': 0.64; 'between': 0.67; 'biggest': 0.67; 'believe': 0.68; 'reverse': 0.68; 'fact,': 0.69; 'yourself': 0.78; '2015': 0.84; 'hard.': 0.84; 'sets,': 0.84; 'to:none': 0.92; 'you...': 0.96 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=v2NNlrLaRyQaOqHVemTsOZNtk4EMMDaDaXCBG4n0wcM=; b=IQhiKkiOQ7YpXkZXJkXBsLgIkgKruAhXdfCv1jnO0Y5eiSdk8Xs6qFeiW0guebjK5O Gc/91+q1RyiCbBkiroMacE1JvQ1u8NBZXJSlAiVqmZ8hm8Fa/caMsA+qStPkclLLRZXs Z4yaGyKJl8WpEw++2uuVilx6fYzdpHXsEexvWMqWZH1OP7e6p95R+z9KVyZJE0hlTqB8 OiIfQRyR0XPS7Yiyd02KzAt/RCfxr5v8nSBIV01FrxBLR/nAcb3AmtmYHblZPZA2LY+Y YzZUdKbVTeZXRh5OGiJojU69Fs9zr/OUmCpp7h3KfYF6GP2G8hWP1mRqLIjlPecAsC2+ mVNg== MIME-Version: 1.0 X-Received: by 10.50.114.35 with SMTP id jd3mr11499178igb.14.1429456508780; Sun, 19 Apr 2015 08:15:08 -0700 (PDT) In-Reply-To: <7tMYw.252071$SO1.39320@fx43.am4> References: <9fc57fc9-0399-4ff3-882a-d041f02827d8@googlegroups.com> <6580b5d5-92f5-4bfa-b1d0-889c69fe82bb@googlegroups.com> <7tMYw.252071$SO1.39320@fx43.am4> Date: Mon, 20 Apr 2015 01:15:08 +1000 Subject: Re: New to Python - block grouping (spaces) From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 43 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1429456511 news.xs4all.nl 2871 [2001:888:2000:d::a6]:50863 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:89157 On Sun, Apr 19, 2015 at 9:38 PM, BartC wrote: > Suppose there were just two syntaxes: C-like and Python-like (we'll put > aside for a minute the question of what format is used to store Python > source code). > > Why shouldn't A configure his editor to display a Python program in C-like > syntax, and B configure their editor to use Python-like tabbed syntax? You still haven't addressed the question of the extent of "C-like syntax" for Python. It's not simply a matter of block delimiters. With git (and I believe similarly with hg, but I'm not sure about smaller and/or proprietary source control systems), you can define a pair of filters which transform a file between the actual source control system and your checked-out version, so (for instance) you could have source control work with four-space indents where you work with tab indents. That one's dead easy. With a little more work, you could probably rig something up to use keywords or symbols to delimit blocks of code; braces would be harder, because Python uses them for dicts and sets, so you'd need some sort of context-aware parsing. But the biggest problem is that you wouldn't actually be changing anything else. You'd end up with a bizarre hybrid that uses a tiny bit of C-like syntax, but entirely Python-like syntax everywhere else. For example, Python doesn't allow this: if condition: for i in range(3): do_stuff() So you'd never truly be able to take advantage of the braces. In fact, all you'd _really_ have would be a way to key in some braces, commit to source control, check out again, and have your indentation auto-fixed for you... and if that's all you want, I think there are editors which make the reindenting of code a ton easier than that! As Dave suggests, make yourself a parser which turns *any* legal[1] Python code into your preferred "C-like" syntax, and another which performs a perfect reverse transformation. I suspect you'll find the task fundamentally hard. ChrisA [1] Coping with broken Python code is going to be important later on, but ignore it for now. It's a ton harder to ensure that you can do a reversible syntactic change on something with syntax errors!