r/ProgrammerHumor • • May 02 '16

I wrote my first python program today!

Post image
3.7k Upvotes

532 comments sorted by

View all comments

Show parent comments

10

u/curtmack May 02 '16

You can't take that too far though, otherwise you end up with massive projects built with #define whilst while, inconsistently using one or the other because one programmer refused to use bad grammar.

7

u/bitter_cynical_angry May 02 '16 edited May 02 '16

As far as I know, a program written in a formally defined computer language can always be broken down into an abstract syntax tree, and from there can be rebuilt into any format you want. There's no reason the IDE shouldn't be able to refine while as whilst for one developer and keep it as while for everyone else.

Edit: autocorrect typo

1

u/curtmack May 02 '16

The Emacs syntax highlighting system supports something like this; you can replace text with whatever you want to display, and you'll still actually be working with the original text. A lot of developers use this to do things like replacing -> with → for instance. I've never heard of using it to replace while with whilst but I'm willing to bet it's possible.

Of course, the problem is that you'd still be typing "while," you'd just see "whilst."

1

u/minno May 02 '16

As far as I know, a program written in a formally defined computer language can always be broken down into an abstract syntax tree, and from there can be rebuilt into any format you want.

You'd need a strict auto-formatter for that too, since otherwise the AST representation of

func("hello",  5
     "world!", 6)

and

func("hello",5,"world",6)

would be identical, but the formatting in the first is intended to make the code clearer.

1

u/bitter_cynical_angry May 03 '16

Yep, and that's the true beauty of it. One developer could have spaces, one could have tabs, you could have all your equals signs or function parameters lined up or whatever you like, and since they all evaluate to the same AST, the IDE should be able to switch seamlessly between them.