Removing curly braces? I have to paraphrase Torvalds on this: > The answer to that is that if you need > more than 3 levels of indentation, you're screwed anyway, > and should fix your program. Breaking the code into manageable chunks is a huge part in writing clear, maintainable software. A high amount of curly braces implies deep nested loops and/or branches, which also implies a high complexity (measured by cyclom…
I don't really see the problem either. A lot of this stuff I see seems to be centered around stuff that 'trips up beginners' What I would like would be a way to portably create a stack frame and pass it around as an object and then call a function with it.
Fixing C
31–40 of 123 posts
Re: Fixing C
#32Closures. This is the only thing that I miss in C. I always want to declare local functions, and return pointers to them.
Re: Fixing C
#33I would add multiple return so api's don't suck.
There you go: struct much_improved_c { ... }; struct much_improved_c an_api_that_doesnt_suck() { ... };
Re: Fixing C
#34Removing curly braces? I have to paraphrase Torvalds on this: > The answer to that is that if you need > more than 3 levels of indentation, you're screwed anyway, > and should fix your program. Breaking the code into manageable chunks is a huge part in writing clear, maintainable software. A high amount of curly braces implies deep nested loops and/or branches, which also implies a high complexity (measured by cyclom…
If it's embedded code, it's quite possible you can't just decompose code into little bitty chunks to avoid nesting, because your maximum stack depth is fixed and very small.
Re: Fixing C
#35Closures. This is the only thing that I miss in C. I always want to declare local functions, and return pointers to them.
Re: Fixing C
#36I would add multiple return so api's don't suck.
There you go: struct much_improved_c { ... }; struct much_improved_c an_api_that_doesnt_suck() { ... };
Re: Fixing C
#37Regarding the curly brackets thing vs. end statements and indentation: How is this a problem with editors/IDEs doing it all for you? If your editor/IDE does not do this, then.. why don't you have this in your setup?
You can do auto-indent in Java, PHP, Perl... but not in C/C++, where you're free to embed curly braces etc. in macros, and it's really common to do so. To make matters worse, you actually need to compile the program in order to determine which macro gets expanded into what amount of braces...
Re: Fixing C
#38Earlier quoted context omitted.
C arrays “know” their size. (String literals do too.)
You can sizeof them if the declaration is in scope. If you pass them as function argument, this information is not obtainable inside function. You have to pass length as well. This is not very elegant and sometimes you elect to process them without using functions just because you can iterate them easier.
Re: Fixing C
#39For projects where you are free to choose your language, Nim is very modern and powerful. It compiles to C so you can use it as easy replacement.
Re: Fixing C
#40The great problem of C is that almost everything is a pointer and they potentially can all be invalid. On top of this there's no easy way to check wether they are valid. This is the reason, why memory safety is so hard to get right with C.