r/cpp • • May 05 '18

CPY (Pre)Compiler: C++ without redundancy

https://github.com/vrsperanza/CPY#cpy
3 Upvotes

15 comments sorted by

29

u/gracicot May 05 '18

using namespace std;

walks away slowly

22

u/jonesmz May 05 '18 edited May 05 '18

Semicolons are implied from line breaks (lines must be marked to continue, not to break)

Picks up pace to brisk walk

Curly brackets are implied from identation

Breaks into a jog

operations(int a, b)
    sum = a + b
    subtract = a - b
    multiply = a * b
    divide = a / b
    return sum, subtract, multiply, divide

Runs flat out

Abort! Deliberately breaks comma operator! I repeat! Breaks comma operator!

Its...... PYTHON! Run for the hills!

6

u/gracicot May 05 '18 edited May 05 '18

I'm also really worried because the code generator assumes that using namespace std; is present in the current file. For example, the multiple return simply inserts "make_tuple(" + <your stuff> + ")", which is just... wrong.

Edit: went too hard, I'll give the author a chance.

4

u/jonesmz May 05 '18

I'm also really worried because the code generator assumes that using namespace std; is present in the current file. For example, the multiple return simply inserts "make_tuple(" + <your stuff> + ")", which is just... wrong. And I can bet on my head it chokes on the first template I feed it.

At the very least, it should be doing

make_tuple(" + move(<your stuff>) + ")

But it doesn't sound like that's the case.

2

u/1-05457 May 05 '18

Haskell does semicolon and brace inference pretty well, so I suppose it could be done for C++. I don't know if CPY is that good though.

2

u/sumo952 May 06 '18

I think C++ is one of the hardest languages to parse though. My guess would be that removing the semicolon doesn't make it easier.

1

u/FKaria May 07 '18

Breaking the comma operator is probably the most inconsequential break really.

I think this language achieves its goal of writing simple code in a simple style. I don't think is aiming to be used for complex template super generic libraries kind of thing

3

u/wqking github.com/wqking May 06 '18

I think it should be walks away quickly because there is even "using namespace std" in the header, how horrible it is!

7

u/jonesmz May 05 '18

You know, while I think this project is going in the absolute wrong direction, I could see the benefit of doing something like

Makes all variables that are not prefixed with the "mut" or "mutable" keyword "const"

Keeps noobs from screwing themselves.

1

u/Leridon May 07 '18

Using "val" as an alias for "const auto" Would be great.

0

u/[deleted] May 05 '18

[deleted]

3

u/redditsoaddicting May 06 '18

I'd prefer a non-preprocessor feature that solves the problem this is solving.

1

u/pfultz2 May 06 '18

Why can't you use template aliases?

template<class X, class Y>
using  SomeThing = Wrapped<X, Y, mixin>;

2

u/[deleted] May 06 '18

In this case it would work, I just wanted to make it trivial.

What if I wanted to swap template to function params?

Also, I'd like to do usual "magic" in the pre-processor as of regular function parameters, like concats and "stringify".