Earlier quoted context omitted.
Every language has inconsistencies, and C is not stranger to that. Much of c++’s baggage is due to C and you carry the same weight. That’s not to say that initialization isn’t broken in C++, but just like many features in many languages (off the top of my head in C - strcpy, sprintf, ctime are like hand grenades with the pin pre pulled for you) don’t use them. There’s a subset of C++17 that to me solves so many issue…
Variables like "valueSet" scream out that the language lacks a Maybe type instead. One of the worst things about C++ is that it's content to basically not bother improving on the C type system.
Exploring Polymorphism in C: Lessons from Linux and FFmpeg's Code Design (2019)
81–90 of 131 posts
Re: Exploring Polymorphism in C: Lessons from Linux and FFmpeg's Code Design (2019)
#82Earlier quoted context omitted.
> weight and inconsistencies of (early) C++ Since very little is ever removed from C++, all the inconsistencies in C++ are still there.
Every language has inconsistencies, and C is not stranger to that. Much of c++’s baggage is due to C and you carry the same weight. That’s not to say that initialization isn’t broken in C++, but just like many features in many languages (off the top of my head in C - strcpy, sprintf, ctime are like hand grenades with the pin pre pulled for you) don’t use them. There’s a subset of C++17 that to me solves so many issue…
Re: Exploring Polymorphism in C: Lessons from Linux and FFmpeg's Code Design (2019)
#83Earlier quoted context omitted.
Variables like "valueSet" scream out that the language lacks a Maybe type instead. One of the worst things about C++ is that it's content to basically not bother improving on the C type system.
C++ has a maybe type. It's called std::optional.
Re: Exploring Polymorphism in C: Lessons from Linux and FFmpeg's Code Design (2019)
#84Earlier quoted context omitted.
The difference between Go and Java is that in Go a type need not declare its adherence to an interface up front—any type that has methods of appropriate names and signatures is considered to implement the interface, even if its designers were not aware of the interface’s existence. (This involves a small bit of dynamism in the runtime; easily cached, though, as the set of methods of a given type and the set of all in…
I don’t agree it’s a structural VS nominal difference. Typescript is structural, but it does have the “implements” keyword. Which makes a million times more sense to me, because realistically when do you ever have a structure that usefully implements an interface without being aware of it?? The common use-case is to implement an existing interface (in which case might as well enforce adherence to the interface at dec…
If "Two" didn't have a "name: string" member, then the error would be on the call to "test".
interface Foo {
name: string
}
class One implements Foo {
constructor(public name: string) {}
}
class Two {
constructor(public name: string) {}
}
function test(thing: Foo): void {
//...
}
test(new One('joe'));
test(new Two('jane'));Re: Exploring Polymorphism in C: Lessons from Linux and FFmpeg's Code Design (2019)
#85Earlier quoted context omitted.
> Well written C tends to be legal C++ also The "well written" remark is relevant. Many style guides will consider implicit void conversions not well written C. Naturally we are now on C23, and almost every C developer considers language extensions as being C, so whatever.
Well written idiomatic C is certainly not valid C++.
Re: Exploring Polymorphism in C: Lessons from Linux and FFmpeg's Code Design (2019)
#86Earlier quoted context omitted.
Every language has inconsistencies, and C is not stranger to that. Much of c++’s baggage is due to C and you carry the same weight. That’s not to say that initialization isn’t broken in C++, but just like many features in many languages (off the top of my head in C - strcpy, sprintf, ctime are like hand grenades with the pin pre pulled for you) don’t use them. There’s a subset of C++17 that to me solves so many issue…
For C users. And C++ users: In C++ we can declare variable in the while or if statement: https://en.cppreference.com/w/cpp/language/while https://en.cppreference.com/w/cpp/language/if It's value is the value of the decision. This is not possible with C [1]. Since C++17 the if condition can contain an initializer: Ctrl+F if statements with initializer https://en.cppreference.com/w/cpp/language/if Which sounds like the…
Also in Java: https://www.geeksforgeeks.org/for-loop-java-important-points...
Re: Exploring Polymorphism in C: Lessons from Linux and FFmpeg's Code Design (2019)
#87For the record, this design pattern is called a virtual method table, or vtable. I'm surprised that this article never mentioned the term. C++ programmers will know this pattern from the `virtual` keyword.
Re: Exploring Polymorphism in C: Lessons from Linux and FFmpeg's Code Design (2019)
#88Re: Exploring Polymorphism in C: Lessons from Linux and FFmpeg's Code Design (2019)
#89The language is called Go. Other than that, yeah doing by hand what C++ and Objective-C do automatically.
Re: Exploring Polymorphism in C: Lessons from Linux and FFmpeg's Code Design (2019)
#90Earlier quoted context omitted.
One of the main uses for interfaces in Go is defining the contact for _your_ dependencies. Rather than saying your function takes a socket, if you only ever call Write(), you can take a Writer, or define another interface that is only the set of functions you need. This is far more powerful than declaring that your type implements an interface up front. It allows for things like e.g. multiple image libraries to imple…
> It allows for things like e.g. multiple image libraries to implement your interface without knowing it That virtually never happens. Seriously, what would be the odds? It’s so much more usual to purposefully implement an interface (eg a small wrapper the writer thingy that has the expected interface) than to use something that happens to fit the expected interface by pure chance. It’s not a structural vs nominal pr…