Live data from Hacker News

Git's list of banned C functions

github.com

511–520 of 639 posts

Re: Git's list of banned C functions

#511

Earlier quoted context omitted.

> I teach at university as external lecturer. Teaching strings in C is the hardest thing I have to do every time. But if you keep up the good work you will one day go from extern void *lecturer; to static const lecturer;

I'm not really const. I'm definitely volatile depending on the budget. It's definitely a side gig.

I need a side gig, for shits and giggles. I miss uni a lot, for the community of it. Would you recommend it?

Re: Git's list of banned C functions

#512
post #45

Earlier quoted context omitted.

Unfortunately, much of the pain with C surrounds dealing with strings. It’s been a bit of a theme on Hacker News for the past few days, but it’s actually a pretty good spotlight on something I feel is not always appreciated - strings in C are actually hard, and even the most safe standard functions like strlcpy and strlcat are still only good if truncation is a safe option in a given circumstance (it isn’t always.) (…

What I don’t understand is why C programmers use the built in strings. It’s like rolling your own sorting algorithm every time you need it. Surely someone could write a better string library in C that hides the complexity. The real problem is that C programmers are apparently allergic to using other people’s code.

I think nearly every C programmer has gone through the phase of Oooh I'll write my own string library! Sure, that works. Except you have to call system libraries and all kinds of other external functions all of which naturally assume the conventional char arrays. So you spend a bunch of time converting back and forth until eventually realizing it's silly, just learn the convention and go with it.

Re: Git's list of banned C functions

#513

Earlier quoted context omitted.

I occasionally adjunct. What students call me at the beginning of the semester is always awkward: Them: "Hello Professor" Me: "Technically I'm not a professor." Them: "Okay, we'll just call you Doctor." Me: "Yeah, about that... not a doctor either." Them: "So why are we paying you?" Me: "Technically, you're paying the school. And the school is paying me... very little" Them: "Answer the question" Me: "Because I know…

I teach first-years in Australia, where boys from private schools call me "sir". When I'm feeling mean, I tell them to drop and give me ten pushups.

> ten pushups

I'm guessing you don't teach computer science

Re: Git's list of banned C functions

#514
post #184

Earlier quoted context omitted.

In my school, we had two days to understand the basics of text editors, git (add, commit, rebase, reset, push) and basic bash functions (ls, cd, cp, mv, diff and patch, find, grep...) + pipes, then a day to understand how while, if/else and function calls work, then a day to understand how pointer work, then a day to understand how malloc(), free() and string works (we had to remake strlen, strcpy, and protect them).…

This heavily filters for people who have had experience with programming in high-school or even before that, there's no way for a programming novice to pass that grueling routine. And then people rhetorically ask themselves why students coming from economically disadvantaged households are under-represented in this industry (one of the best paying industries in this time and age). Stuff like that has got to change.

I don't understand your concern. How is teaching programming in school discriminatory? Would it be better to not teach programming at all?

Re: Git's list of banned C functions

#515

Earlier quoted context omitted.

Whenever I review C code, I first look at the string function uses. Almost always I'll find a bug. It's usually an off by one error dealing with the terminating 0. It's also always a tangled bit of code, and slow due to repeatedly running strlen. But strings in BASIC are so simple. They just work. I decided when designing D that it wouldn't be good unless string handling was as easy as in BASIC.

I’m not sure if it was the original purpose of C, or of it’s what made C popular, but compared to BASIC, processing strings in C was much faster.

Everything was faster in C - it was compiled and BASIC was interpreted.

Better comparison would be between C and Turbo Pascal strings in DOS times. TP strings were limited to 255 characters but they were almost as fast as C strings, in some operations (like checking length) they were faster, and you had to work very hard to create a memory leak or security problem using them.

I've learnt Pascal before C and the whole mess with arrays/strings/pointers was shocking to me.

Re: Git's list of banned C functions

#517

Earlier quoted context omitted.

Whenever I review C code, I first look at the string function uses. Almost always I'll find a bug. It's usually an off by one error dealing with the terminating 0. It's also always a tangled bit of code, and slow due to repeatedly running strlen. But strings in BASIC are so simple. They just work. I decided when designing D that it wouldn't be good unless string handling was as easy as in BASIC.

Mr. Bright, I just want to thank you for creating D. It is by far my favorite language, because it is filled with elegant solutions to hard language problems. As a perfectionist, there are very few things I would change about it. People rave about Rust these days, but I rave about D in return. Just wanted to say thanks (and that I bought a D hoodie).

Thanks for the kind words!

Re: Git's list of banned C functions

#518
post #67

To respond to some of the comments. It is not that there is anything intrinsically wrong with these functions. You can technically use all of them and I have been using all of them, safely, for decades. The issue is they are huge traps to the point that in a larger piece of software one can say "well, it's just not worth it". You can go much, much, much further than that. In couple embedded projects I worked some of…

> dynamic allocation after application has started is banned -- any heap buffers and data structures must be allocated at the start of the application and after that any allocation is a compile time error, how do ensure that?

One way I can think of is to include the banned.h after you have performed all init processes

(It would have to be in the .c files, not the headers, might not be so clean)

Re: Git's list of banned C functions

#519
post #45

Earlier quoted context omitted.

Unfortunately, much of the pain with C surrounds dealing with strings. It’s been a bit of a theme on Hacker News for the past few days, but it’s actually a pretty good spotlight on something I feel is not always appreciated - strings in C are actually hard, and even the most safe standard functions like strlcpy and strlcat are still only good if truncation is a safe option in a given circumstance (it isn’t always.) (…

I teach at university as external lecturer. Teaching strings in C is the hardest thing I have to do every time. The university decided to explain C to first year student without previous experience. My feedback was to do a precourse in Python to let them relax a bit with programming as a concept and then teach C in a second course.

I've studied IT in early 00s in Poland, the course was a little outdated, but it had some advantages.

We've started from 0 with no assumption of any computer knowledge and first 2 years most courses were using Delphi (console only, no GUI stuff, basically it could just as well have been Turbo Pascal, some Linux enthusiasts used FPC instead of Delphi and it worked).

We all complained that we want C++ then, but I've learnt to appreciate Pascal later. After first few months we've known every nook and cranny and there was very little corner cases and gotchas. So basically we focused on algorithms and not on avoiding the traps language set for us.

Most people had no programming experience and after a few weeks they wrote correct programs no problem.

I doubt this would happen if we started with C++ as most people wanted, and I think it's better than Python as a starting language because it teaches about static typing and difference between compile- and run-time.

Sadly it's a dead language now.

Re: Git's list of banned C functions

#520
post #45

Earlier quoted context omitted.

Unfortunately, much of the pain with C surrounds dealing with strings. It’s been a bit of a theme on Hacker News for the past few days, but it’s actually a pretty good spotlight on something I feel is not always appreciated - strings in C are actually hard, and even the most safe standard functions like strlcpy and strlcat are still only good if truncation is a safe option in a given circumstance (it isn’t always.) (…

Whenever I review C code, I first look at the string function uses. Almost always I'll find a bug. It's usually an off by one error dealing with the terminating 0. It's also always a tangled bit of code, and slow due to repeatedly running strlen. But strings in BASIC are so simple. They just work. I decided when designing D that it wouldn't be good unless string handling was as easy as in BASIC.

Hello Walter! All things considered, you are probably the best person to ask for tips on string handling in C.

Would you might sharing the things that you look for, from the obvious to the subtle? I would love to see some rejected push requests if possible. If I were writing C under your direction, what would you drill into me?

Thank you, it is an honour to address you here.

Post reply on HN