Hacker News new | past | comments | ask | show | jobs | submit login
Show HN: Introducting C+ (github.com/orangeduck)
148 points by orangeduck on Oct 31, 2012 | hide | past | favorite | 47 comments



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-... which does some "Object Orientation" in C tricks?


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.


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.


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


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


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.


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

Point about name noted, open to suggestions :)


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


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


> Well Objective C is a separate language entirely.

Not quite; Objective-C is a superset of C. You can write pure C and compile it as Objective-C all day long.

This is an important point because people think their C knowledge doesn't translate to Objective-C, mainly because people say things like "it's entirely different". At its core, it really isn't -- the superset syntax becomes straight C underneath.


Beyond that, even, you can write Objective-C in pure C99. The brackets, class definitions, and all the rest is a sort of syntactic sugar that converts directly to a handful of straight C functions (you can find them all here: https://developer.apple.com/library/mac/#documentation/Cocoa...)


"Bluegoose C runtime"

What are the performance implications of these features? How do they compare with similar C++ functionality, especially things they do at compile-time? Can I have a pretty graph?

What trade-offs were made? Can they be improved? Are certain aspects or semantics optional? Do you pay the price of linking this library simply by linking it, or do you "only pay for what you use"?

Is it safe? Type-safe? If not, what's required to make them safe?

If you don't answer these questions, somebody like me will who's ignorant of how this is supposed to work will produce their own data. That's not good, you understand how it's supposed to be used.


That's a lot of questions. I will do my best to answer them but note I am not trying to sell a language here. I'm just a student and wanted to show an interesting project I'd been playing with.

The performance implications are much like vtable lookup in C++. Generic functions are essentially overloaded and their function pointer looked up at runtime. The main tradeoff over C++ is that rich types don't play well when allocated on the stack as destructors cannot be automatically called on frame exit.

The added semantics are not optional, but you can still program in standard C while avoiding the defined keywords and functions and the interaction should not be troublesome at all. There is no price for linking the library.

It is not type-safe and employs runtime type checking where inserted by the user - but also this allows for duck typing and more generic code so perhaps it is not a bad thing all round.

I hope that helps. Any more questions feel free to drop me an e-mail.


What about "C&"? C and

Short and easily searchable.


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


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.


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.


How's your comment even remotely related to the submission?


You probably could have chosen a less confusing name..


And one without syntax errors.


Disney will soon buy the rights to C, C+, and C++, and come out with C+++ in 2015.


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

Wow. That's my favorite part.


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~!


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.


I think that's actually an issue with 64bit pointers :/


Works on my Mac (with gcc 4.7 :) )


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!


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


Some form of templating would be nice too. Something to replace multi-line macros.


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


> 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.


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.


> ...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.



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.


A+ for clever use of typedef void star


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


Neat!


Wtf


Please elaborate.


Please don't


bad name


0


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"


Perhaps 'it might once have become' would make more sense there, in that it was a development the author thought could have happened in the past but did not?


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?


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...




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: