r/coding • u/brainy-zebra • Mar 06 '21
TIL git devs include a header file to ban certain c function footguns
https://github.com/git/git/blob/master/banned.h39
u/JReddeko Mar 06 '21
I've been programming my whole life and everytime I see a blog or post there is a word that I have never heard before.
I wonder if any other discipline makes u feel dumber the longer you do it.
18
u/veringer Mar 06 '21
It never stops. It's like buzzword-fashion, but for clever metaphors and theorems.
5
u/eloc49 Mar 07 '21
What the actual fuck is a monad?!
3
5
2
u/BoldeSwoup Mar 07 '21 edited Mar 07 '21
https://mikhail.io/2016/01/monads-explained-in-csharp/
Tldr : type that encompass another generic type to add functionality. It can usually output those operation in the same monad type so you can chain those operation with a more fluent syntax (like Linq in C# or streams in Java to manipulate collections).
It's nice to move the boilerplate code out of the way and not clutter your important functions that implements business rules. Or for easy to read test assertions or mockup setups.
actualResult.Should().StartWith("AB").And.EndWith("HI").And.Contain("EF").And.HaveLength(9)
That's a much nicer test assertion than doing it in separate bare statement, isn't it ? (of course it should be capable of telling you which part of the chain screwed it).
Another example would be having a type that implements lazy instantiation for another maybe ? (Like Lazy<T> in C# ?)
I guess the classic example given everytime is the Maybe monad, which encapsulate a type T and perform null checks so you don't have to do it explicitly everytime.
But that's just my understanding from an OOP dev point of view. It's a functional programming concept so maybe I am missing something (oop and functional aren't incompatible I'm just not experienced enough with functional programming).
Feel free to correct me folks.
1
Mar 07 '21
My grandfather is a carpenter and casual boat builder. The 30th boat he built was for my dad, and his last that he’s in his 80’s now. I show him cool carpentry I find on YouTube and Reddit. He is both intrigued and confused. It’s motivation for him to get better.
If he can do that in his 80’s I think we’re all fine to learn something we’ve never seen before.
That’s the beauty of it!
6
11
5
u/dreamer_ Mar 07 '21
That's because Git has safer replacements for them - e.g. internal struct strbuf and associated functions for string management.
5
u/MrBarry Mar 07 '21
Is there a writeup on the pitfalls of these functions? Or should I just Google each one?
1
15
u/dethb0y Mar 06 '21
As well they should. If you have to use something as archaic and inherently unsafe as C, you should be doing everything you can to limit the harm it can do.
7
u/Clifspeare Mar 06 '21
Dunno why the downvotes. He's not saying that C isn't useful or powerful, of course it is. And it's ubiquitous for a reason.
But no one uses (hyperbole. No one should) straight C in a professional context. Technology has come a long way and the cost of failure/bugs is higher than ever. Whether it's just some static analysis tools, a DSL around C, or an intermediate measure like this, C codebases really benefit from supporting tooling.
16
u/introspeck Mar 06 '21
I've written device drivers, embedded systems, and loadable linux kernel modules in straight C. It's worked pretty well.
valgrind and other tools really help.
When I write applications which don't require low-level C coding, I choose Python.
1
u/Spdftz Mar 07 '21
My first thought is to wonder if they are supplying memory safe versions of all those functions? I'd be sad without a vsprintf, though vararg/format functions are fun to write.
33
u/Cossid Mar 06 '21
Functions