hello friends! new(ish)!

C Help and Discussion: Difference between revisions

From InstallGentoo Wiki v2
Jump to navigation Jump to search
>Emil
(Some additions and repairs.)
>Emil
No edit summary
Line 63: Line 63:


- [https://codeberg.org/xolatile/chad Chad]
- [https://codeberg.org/xolatile/chad Chad]
== Advice ==
=== How to be an Above-Average Programmer starting from University ===
<sub>From >>92426366 In >>92422644, slightly edited:</sub>
If you are in University, I think it's a good idea to supplement the classes with your own extra learning in the niches you see yourself in in the future. There's also no harm in learning things earlier than planned in your syllabus (see also: https://sive.rs/kimo). If anything, it will make it easier to get good grades and also solidify the material in your mind by going over it twice. However, it shouldn't be taken to an extreme where you're spending every waking hour in front of the computer and neglect your health or social life. Balance is important too.
University teaches you a lot of things, but there is often not enough time to cover everything in as much detail as needed to actually get good at programming. For example, I learned enough C to write a simple game but didn't know about arena allocators, struct padding, aliasing and restrict, cache locality, CMake. They taught me how to write one-file Python scripts but not how to organize larger projects with modules, virtualenv, requirements.txt, etc.
Above all, it's worth the effort to practice "professional" development early. In a lot of universities you can get by writing many small programs (<1000 lines) so you never get practice with larger ones. Start some multi-month and multi-thousand-line-of-code projects - either personal or a university project that might use in multiple classes. Use all the standard practices: host it on GitHub/GitLab/Codeburg/etc - It can be private if you're shy. Write [https://cbea.ms/git-commit/ good commit messages]; write a nice README.md; use Make/CMake/Meson and write down build instructions; use a readable coding style and refactor from time to time; write some tests with CMocka for the tricky algorithmic parts. After you get some practice, try contributing to open source projects! They often have a bunch of bugs in their issue tracker that aren't a priority but they'll still happily take fixes for.
Editor note: These ideas apply to even if you're not a University student, though you must define your own syllabus and you'll have to do the grading yourself. Start somewhere, and start writting code and try to follow anons advice.

Revision as of 21:14, 29 March 2023

The C Programming Logo
A set of challenges

C Help and Discussion is an ongoing general. In it people discuss C/C++ programming, projects that they and others are working on. Show what your working on, and go mess around someones else's code.

Tools

Building and Build systems

Makefiles

"A Makefile a day keeps the doctor away." - me

Makefiles provide a very useful basis and if you fully grasp them, you can do most anything with enough investment. Though in most cases it's better to use Makefiles for small and simple projects.

Autobuild

A hellish extension of make. Stub.

CMake

CMake is a multi-platform build system that is the defacto successor to Autobuild. It's generally considered to have bad syntax, but can cover most needs with enough effort.

Meson

CMake with better syntax.

Recommended Build Options

Warnings

For GCC, it is generally recommended to use `-Werror -Wall -Wextra -Wpedantic`; and for Clang it's recommended to use `-Werror -Weverything`.

Release options

`-O2 -DNDEBUG` Provides good optimizations, and `-Os` is generally discouraged due to some bad trade offs that may occur reducing optimization greatly.

Debug options

`-Og -g -fsanitize=address,undefined`, use `-ggdb` instead of `-g` if you intend to use GNU Debugger.

Tools like Valgrind, Splint will help you debug and improve your code.

C Misconceptions

C is a small language!

C is often called a small language but this is simply not true. Its small RELATIVE to other languages. The set of information that is C is quite large on its own and takes a long time to master completely ("Master" could be defined as the ability to write a working standards-compliant compiler).

C has no package manager!

C has many, many package managers, one for every GNU/Linux Distribution.

Useful Links

Getting started

- Hello World!

- C FAQ

Challenge

- DPT ROLL

Books

- K&R PDF

- KING PDF

- RMS GUIDE PDF

Notable Projects Summited

- Dotris

- TeaChess

- Chad

Advice

How to be an Above-Average Programmer starting from University

From >>92426366 In >>92422644, slightly edited:

If you are in University, I think it's a good idea to supplement the classes with your own extra learning in the niches you see yourself in in the future. There's also no harm in learning things earlier than planned in your syllabus (see also: https://sive.rs/kimo). If anything, it will make it easier to get good grades and also solidify the material in your mind by going over it twice. However, it shouldn't be taken to an extreme where you're spending every waking hour in front of the computer and neglect your health or social life. Balance is important too.

University teaches you a lot of things, but there is often not enough time to cover everything in as much detail as needed to actually get good at programming. For example, I learned enough C to write a simple game but didn't know about arena allocators, struct padding, aliasing and restrict, cache locality, CMake. They taught me how to write one-file Python scripts but not how to organize larger projects with modules, virtualenv, requirements.txt, etc.

Above all, it's worth the effort to practice "professional" development early. In a lot of universities you can get by writing many small programs (<1000 lines) so you never get practice with larger ones. Start some multi-month and multi-thousand-line-of-code projects - either personal or a university project that might use in multiple classes. Use all the standard practices: host it on GitHub/GitLab/Codeburg/etc - It can be private if you're shy. Write good commit messages; write a nice README.md; use Make/CMake/Meson and write down build instructions; use a readable coding style and refactor from time to time; write some tests with CMocka for the tricky algorithmic parts. After you get some practice, try contributing to open source projects! They often have a bunch of bugs in their issue tracker that aren't a priority but they'll still happily take fixes for.


Editor note: These ideas apply to even if you're not a University student, though you must define your own syllabus and you'll have to do the grading yourself. Start somewhere, and start writting code and try to follow anons advice.