I have a strong Java/Groovy background and I've been assigned to a team that maintain quite a big C code base for an administrative software.
Some pain points, like dealing with blob in the database or generating reports in PDF and Excel have been externalized to java web service.
However, as a Java dev, I'm a bit confused by some aspects of the code:
- it's verbose (especially when dealing with 'exception')
- there's a lot of huge methods (many 2000+ lines method)
- there's no advanced data structures (I miss List, Set and Map a lot)
- no separation of concern (SQL is joyfully mixed all around the code)
As a result I feel that the business is hidden in tons of technical code and my brain, shaped with Object Oriented and a pinch of Functional programming, is not at ease.
The good side of the project is that the code is straight forward: there is no framework, no byte code manipulation at runtime, no AOP. And the server can simultaneously answer to 10000+ users with a single machine by using less memory than java needs to spit "hello world".
I want to learn how to write C code accordingly to commonly accepted modern principles. Is there any commonly accepted principles about how modern C should be written and structured ?
Something a bit like the equivalent of the 'Effective Java' book, but for C.
Edit at the light of answers and comments:
- I'll try to adapt my mindset to C code and not try to mirror it to OOP.
- I've started to scan-read the recommended coding style guides from the comment (The GNU Coding Standards and The Linux Kernel Coding Style).
- I'll then try to propose this code style to my co-workers. The most difficult part might be to convince co-workers that huge method could be split in smaller parts and that to repeat the same 4 lines of error handling code could be avoided by the help of a method.