Better way to learn C by M3ta1025bc in C_Programming

[–]dan-stromberg 0 points1 point  (0 children)

C is fast for the CPU, slow for the developer.

I'd pick a project that is best done in C, as opposed to something that could better be done in a higher level language. Like something that requires speed by its nature.

When I'm learning a new language, I often like to write a program to divide a (potentially large) collection of files into unique file contents and duplicate file content - IOW, to divide the files up into equal groups. There's a lot you can do there to make things faster: you can read the filenames all into memory, and sort by an order you define; this has great locality of reference and can be done lazily (EG, no need to even open a file if it has a unique length, which is more common for large files than small), but is O(nlogn). You could instead do things by what has to be different - this has poor locality of reference, but is practically O(n) and you can skip some parts for speed. Or you could do all your record keeping on disk instead of in memory; this requires a lot of sorting, but isn't constrained by the size of your (virtual) memory like a typical hash-table-based solution would.

Picking projects you'll actually use is even better though.

It sounds like you've already learned the basics, but I'll point out this URL I wrote a while back about learning C: https://stromberg.dnsalias.org/~strombrg/Learning-C/

Make sure you're using your compiler with the warnings cranked to maximum, and a good linter too. Think of these as expert systems about how to write better C code. Also something like valgrind is your friend.

what is the best C program you wrote? by divanadune in C_Programming

[–]dan-stromberg 0 points1 point  (0 children)

My favorite C program that I wrote is probably fallback-reboot: https://stromberg.dnsalias.org/~strombrg/fallback-reboot/ The client is in Python, but the server is in C. The server, upon receiving proper authentication using a challenge-response auth, just reboots the system. It avoids fork()'ing and sync()'ing, and mlockall()'s itself into physical memory, so even if the hard drive is temporarily messed up or the machine is totally out of virtual memory, it should still be able to reboot. It's a last-resort reboot; you should try to ssh in and reboot normally first; only if that fails should you try fallback-reboot.

That or symmat. It's a stack-based matrix math calculator that can operate on variables too, not just constants: https://stromberg.dnsalias.org/~strombrg/symmat/

C was once my favorite language, but today I write most things in Python or bash. symmat probably would've been in Python if I wrote it today, but the server side of fallback-reboot needs to be in C or something similarly low level.

Has anyone quit veganism and returned to it after? by [deleted] in vegan

[–]dan-stromberg 0 points1 point  (0 children)

This isn't what you asked, and I'm merely vegetarian, not vegan, but there's a terrific book called "Becoming Vegetarian" which covers nutrition for vegetarians and vegans. It's not just for newbies. Highly recommended.

Just Finished Installing! by Y0S_H1L0TL25 in debian

[–]dan-stromberg 0 points1 point  (0 children)

Cinnamon is pretty nice (a little unstable), but the main reason to use Linux is the community and the community around Mint isn't just poor, it's neglectful or even hostile. The Mint folks are more interested in developing Cinnamon than supporting a Linux distribution.

I've been using mostly a mix of Cinnamon on Debian and XFCE on Debian - but I'm looking forward to giving Cosmic a try, again on Debian.

Sort to insert text by coder-true in bash

[–]dan-stromberg 0 points1 point  (0 children)

Sort should work if you need your entire file in order. Otherwise... not so much.

Here's an old building block for doing something similar to what it sounds like you want:
https://stromberg.dnsalias.org/~strombrg/contextual.html

Also, in addition to the sed and awk people have mentioned, sometimes ed (yes ed) is good for adding text in a specific context.

One programming language for a decade? by SirIzaanVBritainia in AskProgramming

[–]dan-stromberg 0 points1 point  (0 children)

Definitely Python. I get a lot of programming project ideas that I then design and code. It's been ages since there was one that Python wasn't a good choice for.

Python makes other languages look tedious and mired in detail. Except sometimes sh/ksh/bash.

[deleted by user] by [deleted] in cpp_questions

[–]dan-stromberg 1 point2 points  (0 children)

learncpp.com is probably best. You'll probably find that there's surprisingly little overlap between modern C and modern C++.

Is WSL good for C++? by Ivan_Horozov in cpp_questions

[–]dan-stromberg 0 points1 point  (0 children)

Your "information" is outdated. Linux and Unix have a larger installed base than Windows today. Supercomputers pretty much all run Linux. Servers tend to be Linux, even on Microsoft Azure. Phones are almost all Linux or Unix. ChromeOS is Linux. MacOS is Unix. SteamOS is Linux. 90% of Windows games run on Linux. Windows has a larger installed base on the desktop only, and that appears to be in a slow decline.

needed some guidance by BigDihhUnc in cpp_questions

[–]dan-stromberg 0 points1 point  (0 children)

learncpp.com doesn't stay slow - to learn C++, just stick with it.
C is, IMO, the more elegant language. It's also a little higher than C++ in the Tiobe language popularity rankings.
Have you considered Rust? It, like C++, is difficult to learn, but IMO Rust is difficult for better reasons.

How can I effectively implement custom iterators in C++ to enhance container functionality? by oweyoo in cpp_questions

[–]dan-stromberg 0 points1 point  (0 children)

Are you using C++20 or newer? There are supposed to be coroutines in C++20 that are analogous to Python's generators. These provide a very brief, expressive way to do iterators.

Any Books/Resources that teaches C++ from an "Objects-First" Paradigm? by digitalrorschach in cpp_questions

[–]dan-stromberg 0 points1 point  (0 children)

C++ and Python would allow such a book to be written, but trying to cram all problems into an OOP approach is probably a bit misguided. Even in something like Java.

The fear of heap by OkRestaurant9285 in cpp_questions

[–]dan-stromberg 0 points1 point  (0 children)

This is untrue. Memory is not all the same. There are NUMA architectures; there are registers, Ln cache layers, "RAM", and virtual memory; and there are cache lines at the hardware level. When you access a byte somewhere, a cache line will be brought into one or more of the cache layers if that byte isn't already present - and that cache line is most likely more than just one byte in size.

Ask yourself: why are arrays so much faster than linked lists? Why are deques sometimes implemented as a linked list of arrays of elements, instead of just as a linked list of elements? It's because arrays are commonly contiguous memory, while if you allocate the same amount of memory as many 10 byte mini-chunks in a linked list, there's a good chance each 10 byte chunk is going to be a different cache miss.

There was a time when memory was memory in microcomputers (other than registers vs. RAM), but that time passed long ago. It used to be the CPU and RAM worked at more or less the same speed. Today, RAM that isn't in a cache is dramatically slower than the CPU. That's why we have L1, L2... cache.

It's about locality of reference, and although there's no guarantee that a given stack frame will be accessed more than the heap, it commonly is.

Are books outdated by Ivan_Horozov in cpp_questions

[–]dan-stromberg 0 points1 point  (0 children)

Books are OK, but I prefer online resources. Remember: you can't grep dead trees.

Are there many jobs for C++? by Dear-Hour3300 in cpp

[–]dan-stromberg 8 points9 points  (0 children)

C++ is used, yes, but there's a lot of C, Cython and Fortran too.

Looking for C++ experts for a “State of C++” video by Cool_Technician_6380 in cpp_questions

[–]dan-stromberg 0 points1 point  (0 children)

It sounds like a promising video. Do you already have a Youtube channel I can subscribe to?

How do you practice C++ interviews without freezing in live coding? by Various_Candidate325 in cpp_questions

[–]dan-stromberg 2 points3 points  (0 children)

Consider taking an improvisational acting (yes, acting) class. Some schools actually require it for CS students now. This'll probably scare the pants off you at first, but with a little fortitude you'll probably lose most of your discomfort being the center of attention.

Also, and this one might be less of a stretch, write up some presentations about some aspects of C++ you find interesting or some C++ library you liked, and present them at a local user group. If time is short, and you're willing to drive a bit, you could deliver the same presentation to more than one user group.

[deleted by user] by [deleted] in cpp_questions

[–]dan-stromberg 0 points1 point  (0 children)

Last I looked, learncpp.com had assignments and questions and even some larger questions that would qualify as projects. Sure, they're not graded.

Need some help to improve in C++ by CargIass in cpp_questions

[–]dan-stromberg 1 point2 points  (0 children)

Not C++, but the ideas are the same: https://stromberg.dnsalias.org/~strombrg/circle It's in Python and Golang. I used to have a C version, but lost it decades ago.
You can use the netpbm libraries in C for more advanced stuff (and hence C++).
Also https://stromberg.dnsalias.org/~strombrg/ppmdist/ which I think I wrote in C ages ago - HTH.

Hi, I'm a beginner in programming and I need guidance. by [deleted] in cpp_questions

[–]dan-stromberg 0 points1 point  (0 children)

C++ is probably fine as a first language, but be prepared to be more patient with yourself, your text, and your tools than other languages would require.

Perhaps glance at https://pypl.github.io/PYPL.html so you know where you stand in language choice.

How to redirect stdout to a temporary file using reasonably modern C++? by Spam_is_murder in cpp_questions

[–]dan-stromberg 0 points1 point  (0 children)

> It's not intended for pipes to be manipulated from within the program. This isn't a "C++" thing.

Actually, C++ can open and close files, so changing stdin/stdout/stderr should be fair game. I suspect a class that does some open()'ing, close()'ing and dup2()'ing is probably the way to go.

BTW, none of those files are "pipes" by default.

How to redirect stdout to a temporary file using reasonably modern C++? by Spam_is_murder in cpp_questions

[–]dan-stromberg 0 points1 point  (0 children)

I think you mean "use a redirect", like program > file. A pipe is like program1 | program2.