[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
I recently read that C is easy to pick up and extremely difficult
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /g/ - Technology

Thread replies: 14
Thread images: 2
File: c-language.jpg (7 KB, 299x201) Image search: [Google]
c-language.jpg
7 KB, 299x201
I recently read that C is easy to pick up and extremely difficult to master.

I was like what?
Is it really easy to pick up?
I have javascript and python experience
I feel like I would like to get some hands on C to better feel in linux and to be able to optimize python stuff, so that I could if need be do some C code with true multithreading without global interpreter lock

Anyway, is C really easy to pick up?
>>
>>50763927
Actually it's both pretty easy to pick up AND pretty easy to master as long as you follow the C guidelines in Ch 27 of this book.
http://stroustrup.com/Programming/
>>
>>50764028
>C++
wrong link?
>>
>>50764044
No, read the table of contents.
>>
File: 1437077237840.png (40 KB, 362x362) Image search: [Google]
1437077237840.png
40 KB, 362x362
C is really precise. Memory allocation is done by the programmer, types are static. For string processing this is a nightmare, for heavy computation it's great. For multithreading you've got a few choices.

First one is Pthreads, which is basically the straight up implementation of POSIX threads. You include a library, you've got your standard fork/join and lock/synchronization stuff.

There's also OpenMP, which is fucking awesome: it's a number of compiler directives which you add to your code, which automatically gets converted into the dirty stuff. Let's say we have an array, and we do an independent operation on every element of the array using a for loop: just add "#pragma omp parallel for", compile with -fopenmp and your shit is parallel. Let's say we want to sum it together instead into a variable called result, then we do "#pragma omp parallel for reduction (+:result)", and bam, shit is done. Have multiple tasks to do? Wrap each of them in a block with "#pragma omp section" at the top, wrap that in a block with "#pragma omp parallel sections" and your shit is done. OpenMP makes parallelizing computational code a lot easier, and is especially great when parallellizing existing single-threaded code (because shoving pthreads into existing code is ugly as fuck). Picture related, OpenMP is comfy.

If you want to go big and run it on a cluster of computers, look into MPI. It's a system which allows you to run a program on multiple computers and pass messages and data between them. It has all the synchronization stuff (no shared data though, you need to send that shit over). It's a bitch to work with, it sees every CPU as a seperate computer (although I've seen it being used in combination with OpenMP), but fuck it, doing shit on clusters is fast as fuck.
>>
>>50764337
What about the boost library? I used their multithreading tools and it wasn't bad. Not that I have experience using anything else to compare it to.
>>
C is easy as fuck to pick up.

There are like 4 keywords.
You can't do anything more complicated than a fucking loop.
>>
>>50764389
Boost (which is C++, not C by the way) is nice, it has more nice stuff like thread grouping, and using futures/promises to pass data is a really clever language feature. The basic idea is the same as POSIX threads though: fork threads which each execute a certain function, have some basic stuff for locking/synchronization/data protection (mutexes/locks/barriers), have some work sharing constructs (queues,doing stuff based on thread id).

Tbh I don't use Boost often. I work in IT at my university on the team that helps scientists prepare their programs to run in parallel on our cluster (150-something nodes, each 24 cores) and I usually do the C stuff, not C++.
>>
>>50764447
Lambda calculus is easy to pick up. There's like 3 different types of expressions. You can't fuck up.
>>
>>50764028
Got a link to a PDF of the second edition?
>>
>>50763927
C and Lisp are very easy to pick up and moderately easy to master because of their non-bloated core languages, but they're both tedious to work with and maintain since every useful pattern is ad-hoc boilerplate.

"bloated" languages internalize more occasionally useful functionality at the cost of taking longer to learn and making abuse of language features (including actual bloat) much easier.

Yes, you can write something as big and complex as the Linux kernel in C, but it takes countless hours to familiarize yourself with all the bullshit naming conventions, preprocessor macros, etc. when trying to read through an existing codebase like that.
>>
>>50763927
>>
C is easy in the sense that it's easy to learn all the features quickly, but hard to fully utilize since the tools are few.
>>
>>50763927
>I have javascript and python experience
>Anyway, is C really easy to pick up?
Because of your Python background this (fully free) book makes it easy http://c.learncodethehardway.org/book/

Think of learning C from a Python background like learning Latin when you know Spanish
Thread replies: 14
Thread images: 2

banner
banner
[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y] [Home]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.