Live data from Hacker News

Cello – A library that brings higher level programming to C

libcello.org

71–80 of 158 posts

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

#71
post #61

Earlier quoted context omitted.

"everything's an int" I don't understand this. Floating point values aren't ints. I suppose strings are integers because they're made up of 8-bit chars (which are basically ints), but I don't understand how that is advantageous or helpful.

He was trying to illustrate the concept that in C you deal directly with blocks of memory. It can be useful because instead of worrying about the implementation of the language which you're using, you can think about what the hardware is doing and understand what's going to happen based on that. So, for example, you know if at offset 0xDEADBEEF there is are 8 bytes which are holding a number that you want to use, you…

> So, for example, you know if at offset 0xDEADBEEF there is are 8 bytes which are holding a number that you want to use, you can access that chunk of memory and use it however you want. And you can interpret it how it is appropriate for your use case, for example reading it into a string, or an int.

Except these days with strict aliasing that's not true. If you access memory through a pointer of the wrong type, you've probably committed the crime of undefined behavior, for which the compiler might punish you by breaking your code - but probably won't, leaving the bug to be triggered in the future by some random code change or compiler upgrade that creates an optimization opportunity.

Admittedly there are ways to avoid undefined behavior, but still. C gives the compiler a lot of leeway to mess around with your code.

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

#72
post #56
post #22

Earlier quoted context omitted.

> Compile times aren't that slow I beg to differ. C++ encourages placing more code than strictly necessary into header files. Even the standard headers such as add considerably to the compile time, and they keep getting larger with every revision of the standard. When you are making incremental changes, it accumulates to a lot of time spent waiting.

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…

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

#73
post #54

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

I believe those things are exactly what make it higher level. Unless I'm misunderstanding your question, all that makes a language higher level is the amount of abstraction between the human and the computer.

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

#74
post #59

There are several reasons why people use C, one of them is that the language makes it very explicit what generated code is going to look like. That's one of the reasons why Windows kernel is written in C ( https://msdn.microsoft.com/en-us/library/windows/hardware/ff... , https://view.officeapps.live.com/op/view.aspx?src=http://dow... ). Libraries like this obfuscate source code.

A problem with C in modern usage is that many people believe this to be more the case than is warranted.

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

#76
post #54

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

What makes [your favorite language] "higher level"? It looks like syntactic sugar on top of assembly language.

It's higher level because it provides abstractions that improve the language's expressiveness.

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

#77
post #24

Earlier quoted context omitted.

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

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 system (which it assumes to an nth degree---sizeof(int) == sizeof(long) == sizeof(void *)) and promptly crashes on a 64-bit system.

Horrible, horrible code.

You can write clean C without casts and treating everything as an integer, but you have to start your code with that goal.

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

#78
post #24
post #18

Earlier quoted context omitted.

That's like saying "Why not just use lisp?" to a python programmer. They're entirely separate languages (albeit it they do share some commonalities, but not as many as you might think). C is my main language and I dabble in C++. I really dislike C++. I love C. I welcome any efforts to add a bit of higher level functionality to C. I have no desire (ever) to switch to C++.

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

As someone who likes C, I'd like to add a bit of a different look:

The aspect that I love about C is how easy it becomes to read. C offers a (arguably) nice programming interface while not allowing the programmer to hide very many things that are going on. C allows you to make nice abstractions, but those abstractions are still built upon the same basic concepts that C supports, and these abstractions generally don't fundamentally change how the language works, so you can very easily tell the control flow of your program if you simply understand the interactions between the basic parts in use.

Now that said, I'll be the first to say that I think C could benefit from a variety of different features (Some from C++, some from others, and some unique to C), and I could easily give you a fairly long "wish-list" I have for C. But, the clear nature of C is a huge advantage that I think is underrated, and is something that you really can't get back in a language once you lose it.

When you (or I) read a piece of C++ code, there are a lot more details you have to take into account then when you read a piece of C code, simply because C would force the writer to be more explicit in what they are doing in those cases.

Again though, I'll make it clear that I don't think C is the be-all end-all of languages - in particular I'm excited to see how Rust goes - but I do think it has traits that are very nice but largely ignored in most of the current languages in favor of adding lots of different ways to write your code.

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

#79
post #29

Earlier quoted context omitted.

Sure: struct Foo { int virtual; };

You're being pedantic about reserved words?

I had that same problem. I wrote a C library [1] that has a structure field named "class". It's "class" because the protocol being described (DNS) calls that particular field "class" [2]. And I'm not about to pay lip service to an abomination like C++ [3][4].

[1] https://github.com/spc476/SPCDNS

[2] https://github.com/spc476/SPCDNS/blob/ca5052c3d0c3252071a18e...

[3] I am NOT a fan of C++.

[4] But I had to anyway, but I used the C pre-processor to rename the field.

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

#80
post #71
post #61

Earlier quoted context omitted.

He was trying to illustrate the concept that in C you deal directly with blocks of memory. It can be useful because instead of worrying about the implementation of the language which you're using, you can think about what the hardware is doing and understand what's going to happen based on that. So, for example, you know if at offset 0xDEADBEEF there is are 8 bytes which are holding a number that you want to use, you…

> So, for example, you know if at offset 0xDEADBEEF there is are 8 bytes which are holding a number that you want to use, you can access that chunk of memory and use it however you want. And you can interpret it how it is appropriate for your use case, for example reading it into a string, or an int. Except these days with strict aliasing that's not true. If you access memory through a pointer of the wrong type, you'…

Strict aliasing does not preclude using the bytes however you want. All that does is prohibit type casting in certain situations. By using different syntax you can still interpret the bytes how you want to (even if, in extreme situations, you might have to resort to using a memcmp in order to do so).
Post reply on HN