Comments by "" (@jboss1073) on "ThePrimeTime"
channel.
-
2
-
2
-
2
-
2
-
2
-
2
-
2
-
2
-
2
-
2
-
2
-
2
-
@NoX-512 The paper, when it was published, ranked Rust second place right behind C and ahead of C++ (top few languages in the Time measurement, in order and with multiplier for how-many-times-slower-than-C (rather, how many times slower than the first language, which happens to be C): C = 1.00, Rust = 1.04, C++ = 1.56, Ada = 1.85, Java = 1.89, Chapel = 2.14, Go = 2.83).
However, the website has measurements that have been updated to 2021, I believe, from the 2017 date of publication of the paper. As it stands by those more recent measurements, Rust is now = 1.00, meaning it is just as fast as C. Indeed the Programming Language Shootout uses 10 algorithms to measure the speed difference between C and Rust, and each of those languages wins on 5 algorithms, making it a perfect tie for fastest language between C and Rust. C++ has not closed the gap (it kept being 1.56 times slower than C). Hence the old myth that "Because you can write C++ programs that is essentially C code" does not seem true.
Also, a reminder that C++ is not a superset of C.
2
-
2
-
2
-
2
-
2
-
2
-
2
-
2
-
2
-
2
-
2
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
@AllanSavolainen "so if I have a tree in C made of struct nodes, it isn't typed?"
Correct, it is not typed. C does not have Computer Science Types, it has Computer Science Tags. Types are the elements of Type Theory in Computer Science, where Functions are Paths between the Types.
"Could you give a concrete example of something tree-like that C cannot do?"
Yes, C cannot inherently understand algebraic types such as a variant tree that might have different branches and leaves with varying structures. For example, in languages that support algebraic data types, like OCaml or Haskell, you can define a tree where each node can be either a Leaf with some value or a Branch that connects two subtrees, and the compiler will enforce those distinctions across the entire program. The compiler understands the structure and can infer or enforce the proper type usage without additional effort on your part.
In C, you would need to use structs and manually manage the interpretation of the tree. C doesn’t understand the tree as a singular type—it only sees the individual fields within the structs. You would have to implement all the logic yourself, handling pointers and manually verifying which type of node you're dealing with. There's no automatic pattern matching or type safety for these variant-like structures.
Hence, a concrete example of something tree-like that C cannot do is an algebraic tree where nodes can hold different types of data, such as a variant tree with different node types like Leaf Int, Leaf String, or Branch (Tree, Tree). In a language with algebraic data types, the compiler can enforce that only valid branches and leaves are combined in accordance with the defined type. It will also automatically handle different operations depending on the specific form of the node. C, on the other hand, has no concept of enforcing this; you would need to implement all validation, type checking, and interpretation manually, with no built-in language support for pattern matching or managing the tree in a type-safe manner.
So in C you can never truly get a Tree, which is a well-defined Type in Type Theory within Computer Science - it is defined abstractly solely by its operations. In a language that understands true types, the tree's behavior and structure are inherently tied to the rules of the type system. Operations like traversals, insertions, or transformations are governed by the formal type system, ensuring that the operations remain valid and consistent within the type's definition.
C, however, lacks the mechanisms to define such abstract types. It relies on tags (e.g., struct, enum, int, double), but those are just labels for data or groups of data; they don’t carry the semantic weight of a true type. A "tree" in C is just a collection of pointers and structs with no deeper understanding by the language of what makes a tree a tree. The compiler doesn’t know about the invariants or rules that are essential to the abstract concept of a tree; those are left entirely to the programmer to enforce manually. This is a fundamental difference between a language like C, which deals with memory layout and tagging, and languages with algebraic types that embody the abstract, rule-based nature of true types.
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1