

Show HN: Introducting C+ - orangeduck
https://github.com/orangeduck/CPlus

======
meta
Cool idea.

I am confused by the implication of this code

    
    
      var prices = new(Table, String, Int);
      put(prices, $(String, "Apple"),  $(Int, 12)); 
    

Stack objects are created with "$" so these are on the stack and then placed
into the Table? So if this was in a function and the function returned, the
Table (lets assume it was global) would now be pointing to destroyed stack
variables? Is that the correct interpretation?

Is this all done with header files and the preprocessor? It looks like that is
the case - if so, I am impressed at the dances you got it to do ;) Also, have
you read [http://www.amazon.com/Interfaces-Implementations-
Techniques-...](http://www.amazon.com/Interfaces-Implementations-Techniques-
Creating-Reusable/dp/0201498413/) which does some "Object Orientation" in C
tricks?

~~~
MetallicCloud
I'm just guessing here, but I assume the variables are created on the stack,
then copied into the table object, rather than references being passed to the
table. So when the function would end, the original variables would be
destroyed, but the copies would remain.

~~~
orangeduck
This is correct. "Table" is a datatype which copies the values into the table,
while "Dict" is a data type that holds references to the objects. The same
semantics hold for "Array" and "List".

Although not perfect this was probably the best way I could have designed such
structures. There is some info in the header files as to how to use them.

------
troymc
A resume that said the applicant had programmed with C, C+ and C++ used to be
a tell. Not any more, I guess.

~~~
philbarr
My local bookstore had a sign in the software development section saying "C,
C+, C++". I can't point and laugh anymore :(.

------
codewright
How is this different from Obj-C? Seems mostly like syntax sugar on top of
what already exists in C.

The call and call_with are intriguing though.

Please change the name to something searchable and easily remembered before
it's too late.

~~~
orangeduck
Well Objective C is a separate language entirely. This is just a library for
GNU99 C.

Point about name noted, open to suggestions :)

~~~
skrebbel
"Mediterranean C". Fits, because it's more comfortable, more laid-back, less
worrying-about-the-future C programming (si si, we typecheck mañana!).

~~~
inoop
On the other hand, this language appears to be working.

------
sverige
If only you had been around during my first interview when I told the
recruiter that I knew C, C+, and C++.

------
jamesaguilar
IMO, any new language that has inclusion as a mechanism for modules is not
just at a developmental dead end, it's over the curb at the end of that dead
end and in the retention pond beyond.

The parser and compiler should only need to examine each source file once.

~~~
skrebbel
This isn't a new language. It's a C library.

ps. Of course that does not invalidate your point, which I fully agree with.
It's just on the wrong thread.

------
nthitz
You probably could have chosen a less confusing name..

~~~
CarstenW
And one without syntax errors.

------
michaelfeathers
> What I don't enjoy in Haskell is writing small detailed algorithms in a
> functional style.

Wow. That's my favorite part.

------
shadowmint
Had a play with it; few oddities, but this is pretty cool.

The use of the $ function is totally not portable though, which is a bit of a
pity.

Doesn't compile on a mac either; bunch of warning about pointer size that are
being treated as errors by -Werror

Still, nice work~!

~~~
orangeduck
Yeah using $ was pretty cheeky. I use a few other GCC specific features such
as nested functions, which is why I specify that the standard is GNU99 rather
than C99. If you have any errors on mac please post a bug report as I don't
have a machine to test on! Thanks.

------
Meai
I have two things that would make me very happy in C: Overloadable operators
and constructors/destructors. I have not been able to come up with a way to do
that yet, but maybe if I change the entire way I write C like you did with the
syntax changes, it might actually work. I'm going to have to think about that!

~~~
dietrichepp
Out of curiosity, what's wrong with C++? You can always -fno-rtti -fno-
exceptions disable everything, then avoid classes and templates.

------
IsTom
> What I don't enjoy in Haskell is writing small detailed algorithms in a
> functional style.

You can hop around this easily using the ST monad. It's less elegant than
usual Haskell and often less elegant than languages where mutation is
'native', but it does its job.

------
dysoco
I dislike the way you declare variables, I'd rather prefer the classic: "int x
= 5;" but with some syntactic sugar for Stack/Heap.

It's interesting anyways, I love the simplicity of C but agree that it's a bit
"outdated", and I dislike the radical change of Go.

~~~
stcredzero
_> ...I dislike the radical change of Go._

Funny, but the common criticism in the days when Go was first released was
that it was not radical enough.

------
ryanashcraft
I was working a similar project a few months ago. Wish I hade more time to
complete. Mine was a bit more of a ripoff of Obj-C than anything.
<https://github.com/ryanashcraft/Classified-C>

------
prtamil
Every Smart guys is trying to bring Lisp's functionality in C Syntax. But i'm
stupid , i directly use Lisp. Even its hard and that's why i'm stupid.

------
eungyu
A+ for clever use of typedef void star

------
taken
how about adding a macro var(name, type, value) -> var name = $(type, value)?

------
crudbug
Neat!

------
areorui
Wtf

~~~
3rd3
Please elaborate.

~~~
robomartin
Please don't

------
nsp
0

------
codgercoder
bad name

------
nnq
it always annoys me when people can't properly _write_ about what they've
done. For example, the description says, with reference to C: "I've turned it
into something of a dynamic and powerful functional language which _it might
have once been_ " ...is his wording wrong or what? ...'cause C _has never
been_ a "powerful functional language"

~~~
rytis
not everyone is good at writing and expressing themselves in written language.
quite a lot of good engineers actually struggle with this. definitely no need
to be "annoyed", may be try helping him out?

~~~
nnq
I don't mean literary style or PR magic or anything, just using the words
right so what comes out is exactly what you mean, not something that means
something different but you have to use the context to understand what he
probably thought about when writing that... If one can express his thought in
a programming language, one can also use basic grammar like tenses and modes
to say what he means... all this "words don't matter" attitude is what
eventually ends up spreading and making _wonderful_ pieces of software
engineering unusable because of broken docs...

