Live data from Hacker News

Cello – A library that brings higher level programming to C

libcello.org

81–90 of 158 posts

Re: Cello – A library that brings higher level programming to C

#81
post #77

Earlier quoted context omitted.

I'm not the parent, but C has a certain simple elegance: everything's an int; those things which aren't ints (e.g. compound structures like structs and arrays) are represented using pointers and offsets, so in a sense they're also ints; except for floats, but meh. In C++, everything is an int; except for objects; and templates; and lambdas; and classes; and exceptions; and all the other things which keep getting chuc…

Yeah, that phrase "everything's an int" scares me (and I'm a C programmer---been programming in it since 1990). At one time I was playing around with Viola ( http://www.viola.org/ ) (quite possibly the first graphical web browser). The code is a mess precisely because it grasps the "everything's an int" and doesn't let go. Once you get it to compile (and out of the box it doesn't any more) it barely runs on a 32-bit…

As a C programmer, I would also agree. "Everything is an int" is not a good way to be thinking about things. There's a reason that `intptr_t` exists. Well written C shouldn't rely on any integers being specific sizes or the same size unless you're using the standard types for that purpose (Llke `uint8_t`, `uint32_t`, etc.). Even then, you probably don't need them in a lot of cases, and you should basically never be casting integers into pointers unless you're using the above `intptr_t`, or `uintptr_t`. Even then, you're probably still better off just making your life simple and use a `union`.

That said, I would argue that minimal explicit casts is a pretty good goal for any C programs - I find that crazy casting tends to be a sign something could be done better. But obviously, casts are definitely necessary in some instances, so it's not like "castless" code is guaranteed to be the right way to do things anyway.

Re: Cello – A library that brings higher level programming to C

#82
post #54

What features make it "higher level"? It looks like syntactic sugar on C code without any real improvements (aside from GC).

I've used Cello for a few side projects, and it doesn't even really feel like C in the end.

Just a few off the top of my head:

* No need to specify type. Use var.

* Simpler for loops

* Inbuilt types for Hash Tables

* File types, making file reading much easier

* Function types, making it easier to pass functions around

* Doctype access

* Threads & Mutexes

* Format strings

* GC (with ability to turn C-types into Cello-types for GCing.)

It is fundamentally syntax-sugar, but enough that what you end up with doesn't necessarily look like C at the end.

    with(f in new(File, $S("test.txt"), $S("r"))) {
      var k = new(String); resize(k, 100);
      var v = new(Int, $I(0));
      foreach (i in range($I(2))) {
        scan_from(f, 0, "%$ is %$ ", k, v);
        show(k); show(v);
      }
    }
(From: http://libcello.org/learn/file)

Re: Cello – A library that brings higher level programming to C

#83
post #25

IIRC Cello doesn't enforce type safety, which means you can foldl but it's not much different from writing foldl in C and using void pointers everywhere. I had thought about trying to make a type-safe version of Cello but I eventually realized that I can't do it in cpp so at that point it became its own language and too much work (I did not write Cello).

I'm going to say you're right, given one of the first declarations is

    typedef void* var;
Cello is extremely impressive and could be fun for hobby projects, but for something you'd actually want to use on a real product you'd be better off just creating a new language (it could compile down to C even, like Vala did).

Re: Cello – A library that brings higher level programming to C

#84
Looking at the code, a great deal of this is non-portable and/or U.B, so I would hesitate to call it C. And I'm not talking about some hypothetical problems, but stuff that should surface quite soon. For example, this is how stack allocations are made:

    #define alloc_stack(T) ((struct T*)header_init( \
      (char[sizeof(struct Header) + sizeof(struct T)]){0}, T, AllocStack))
So far as I can see, there are basically no alignment guarantees here - the returned pointer to the char array is not guaranteed to be aligned properly for Header (which is a struct of a single void* field), nor is there any attempt to align T inside the array. If things get misaligned, on x86 and x64, it'll work (but possibly much slower than normal), but on e.g. ARM you'll get all kinds of weird things happening.

Re: Cello – A library that brings higher level programming to C

#85
post #72
post #56

Earlier quoted context omitted.

use precompiled headers?

Precompiled headers never worked well due to a variety of limitations. C++ modules, on the other hand, will be like precompiled headers done right. If they ever get standardized. They didn't make it into C++17, and the prototype implementations in Clang and MSVC are incompatible with each other, but I guess it'll happen someday…

>Precompiled headers never worked well due to a variety of limitations.

want to elaborate? i use MSVC's implementation and never encounter any problems with it. then again, i also don't work on large projects, so i would like some insight.

Re: Cello – A library that brings higher level programming to C

#86

Earlier quoted context omitted.

C++ isn't strictly a superset of C! Which I always found crazy. Some C will not compile for C++.

Can you provide C code that will not compile with c++ compiler?

    #include 
    int main() {
        int *x = malloc(sizeof(int));
        return 0; 
    }

Re: Cello – A library that brings higher level programming to C

#87

Why not just use C++?

Cello and C++ are have very different design goals. Cello is essentially a dynamic language implementation on top of C, and uses runtime reflection in places where a C++ programmer would probably prefer compile-time template hackery.

Idiomatic C++ is not like Cello at all. But it still allows you to do all things that Cello does - and most of them wouldn't be macros then, but classes and overloaded operators on them.

Re: Cello – A library that brings higher level programming to C

#88
post #63

Earlier quoted context omitted.

And make sure Iron has a small group of annoying, hardcore fans who relentlessly disrupts any thread about C or indeed programming in general with their ham fisted advocacy.

Can you please point me to where that's happening?

https://news.ycombinator.com/news

Re: Cello – A library that brings higher level programming to C

#90
post #24

Earlier quoted context omitted.

What do you love about C and hate about C++?

C++ is very complicated. C is basically the simplest possible programming language, and the closest to the API actually presented by the processor (i.e., assembly language)

That would be Forth
Post reply on HN