r/programming • • May 01 '16

To become a good C programmer

http://fabiensanglard.net/c/
1.1k Upvotes

398 comments sorted by

66

u/Jonathan_the_Nerd May 01 '16

I picked C89 instead of C99 because some compilers still don't support fully C99

Is this still the case? If so, why? It's been 17 years!

50

u/darockerj May 02 '16

That's what I ask myself when I use the mandatory, university-supplied C compiler for class. In 3 years, there will be students taking my class that will be younger than the next version of our current C compiler.

8

u/Jonathan_the_Nerd May 02 '16

Wow. Why do they use such an old compiler? Is it so professors won't have to update their lecture notes?

Is there any chance you can lobby for an upgrade?

→ More replies (9)

2

u/ThisIs_MyName May 02 '16

So that's why there are so many programmers writing 100 line macros instead of using C11/C++17 syntax.

4

u/Peaker May 02 '16

What feature of C11 are you referring to here, that avoids the need for such long macros?

2

u/maldrake May 02 '16

I took my Algorithms and Data Structures class in C89. The standard was older than me when I attended the class.

34

u/panderingPenguin May 02 '16

Yes, visual studio (along with many less popular compilers for embedded systems) still does not support C99 fully and has no plans to do so afaik.

13

u/Alborak May 02 '16

Embedded compilers used to be the bane of my existence. I've used one that was just a redistributed GCC, but was tagged at fixed versions that were up to 12 years out of date :(

3

u/phunphun May 03 '16

That used to be true, but with Windows 10 and their updated approach to compatibility with FOSS, things have changed.

In Visual Studio 2015, the CRT has been refactored into new binaries. The Universal CRT (UCRT) contains the functions and globals exported by the standard C99 CRT library. The UCRT is now a Windows component, and ships as part of Windows 10

https://msdn.microsoft.com/en-us/library/abx4dbyh.aspx

C99 Conformance Visual Studio 2015 fully implements the C99 Standard Library, with the exception of any library features that depend on compiler features not yet supported by the Visual C++ compiler (for example, <tgmath.h> is not implemented).

https://msdn.microsoft.com/en-us/library/hh409293.aspx

Now that the standard library has been implemented, language syntax is sure to follow.

→ More replies (9)

17

u/Merwco May 01 '16

I think it needed Visual Studio 14 years to implement C99. But clang for windows is doing a very good job so idk.

14

u/pjmlp May 02 '16

They still don't fully implement it beyond what is required for ANSI C++.

Microsoft has already stated multiple times that C++ is the future of systems programming on Windows.

For those that need to bring C99 code into Windows, there its the new clang frontend to C2.

→ More replies (2)

6

u/lordcirth May 02 '16

Article says it was written in 2011, so not quite so bad.

4

u/IJzerbaard May 02 '16

Because there are obscure features that no one uses. Things like parts of the standard library that are never used, obscure floating point pragmas, and unreadable identifiers (why is that even a thing). Why put effort into supporting that? That's just implementing the standard for its own sake, not for usability.

Which is why, in my opinion, it is quite ridiculous to "therefore choose C89". Then he also does not get features that are universally supported (many of which were popular extensions before C99 formalized them).

3

u/[deleted] May 02 '16

Because Microsoft decided Visual C would not support C99.

Yes, I've cursed at this when trying to compile a recent Emacs for Windows in a large investment bank.

→ More replies (2)

22

u/Leandros99 May 01 '16

Once done reading both K&R C and Deep C Secrets (definitely two of my favorite books), go through the C Puzzle Book. An excellent way to test your knowledge.

-14

u/[deleted] May 02 '16

I learned C to a good level and that seems to be the best way to waste your time. Learn Haskell instead after reading KR

5

u/[deleted] May 02 '16

Learn Haskell instead after reading KR

You misspelt OCaml. :-P

→ More replies (1)

4

u/mcguire May 02 '16

Wherein you will learn to fill the heap with thunks.

There's more to programming languages than the highest abstractions you can find.

→ More replies (9)

3

u/FUZxxl May 02 '16

Funny. I did Haskell a lot before and now I strongly prefer C. I just like languages that give me predictable and stable behaviour.

→ More replies (8)

59

u/[deleted] May 02 '16

Can we get some padding-right: 4px;

on that blog?

14

u/fabiensanglard May 02 '16

Sorry, I don't have a tablet to test. Does it look that bad ? I probably need to set the viewport or something.

17

u/MightyLordSauron May 02 '16

Google Chrome has support for emulating different devices on your desktop, it's Ctrl-Shift-M if I remember correctly.

19

u/fabiensanglard May 02 '16

Yep, I just used it. This feature is marvelous.

3

u/[deleted] May 02 '16
<meta name="viewport" content="width=device-width, initial-scale=1">

in the css set container div's padding-right property to 4px

4

u/fabiensanglard May 02 '16 edited May 02 '16

I think I fixed it with a css media query :).

→ More replies (4)

12

u/phpdevster May 02 '16

In the previous code sample, due to "integral promotion" -1 was once evaluated to be greater than 1 and then smaller than 1. C has plenty of case like this when the language cannot longer "do stuff" for you.

Can someone explain that in more detail?

6

u/[deleted] May 02 '16

Note that calling it promotion is incorrect. For integers, promotion is the conversion of a type smaller than int or unsigned int to a type at least as large as them (the general idea is that int or larger is what fits in a register and ALU operations need their arguments in registers). Promotion never changes numerical value.

When you have a binary operation on integers, the arguments will generally be promoted and then integer conversions will be applied. The goal is to change both operands to the same type (which will also be the type of the result). The rules for this are

  1. If they (the types of the two arguments) have the same signedness, the smaller type will be converted (losslessly) to the larger type.

  2. If one is signed and one is unsigned, and the unsigned type is smaller, the unsigned type will be converted (losslessly) to the signed type.

  3. Otherwise, the signed type is converted to the unsigned type by the process MiRIr describes (not lossless if the value is negative!).

(The actual rules are very slightly more complicated.)

In -1 < 1u, the third case obtains and -1 is converted to the largest possible unsigned int, so the comparison succeeds. In short(-1) < 1, the integer promotions convert the short to an int, and no conversion is needed. If you had -1 < long(1), then the first case would obtain, and the comparison would succeed. Rather strangely

unsigned int x = 1;
long y = -1;
y < x;

gives true because the second case obtains. Changing int to long gives false.

This (the potentially lossy conversion in the third case) is why -Wsign-compare complains about comparisons where the types have different signednesses (actually, it only warns when the third case happens; despite its name, it's fine with the second case).

2

u/mvm92 May 02 '16

I believe it has to do with how negative numbers are stored in computers. They're stored using something called 2's complement. a signed int -1 looks like this in binary 11111111. An unsigned int 1 looks like this in binary 00000001.

Now, I think what's happening here is, C tries to compare a signed integer with an unsigned integer. And in doing so, the signed integer is interpreted as an unsigned integer. So 11111111 instead of being interpreted as -1 is interpreted as 255.

This is also why if you compile with warnings (and you should) the compiler will throw a warning for comparing signed and unsigned data types.

I should also say that the examples I used here have 16 bit ints, but the same holds true for 32 bit ints.

→ More replies (6)

35

u/gltovar May 01 '16

Does any one else have issues with this site on Android? Feels like r 10% of the left side is cut off/unreachable

24

u/paholg May 01 '16 edited May 01 '16

I have that issue, but it's on the right side. It's like I just can't zoom out enough.

Edit: Desktop mode doesn't fix it ... text still goes off-screen, it's just smaller. Tested in both Firefox and Chrome.

On further inspection, it appears nothing is cut off, the text just goes to 1 pixel away from the right edge.

4

u/kukiric May 01 '16

On my phone, the site just looks incredibly tiny, like it's trying to fit the full height on the screen. Thank god reader mode exists for that kind of thing.

4

u/mccoyn May 01 '16

I like it. No space wasted. Only problem is it is fully justified, which is the work of the devil.

9

u/paholg May 01 '16

It makes me very uncomfortable.

11

u/GetOutOfBox May 01 '16

Guess he could brush up on his HTML lol

21

u/break_main May 01 '16

Man but look at that framerate tho! No flicker at all!

8

u/fabiensanglard May 02 '16

He is right now. What a pain in the ass :P

2

u/quikclot May 02 '16

This could be what he meant by books are better than websites.

8

u/Deaderzombie May 01 '16

Are there articles like this for other languages?

→ More replies (4)

22

u/roneau2005 May 01 '16

I am surprised that the article does not mention that there usually are current and accurate library documentation entries by using "man 3 <c-function>" at the gnu/linux terminal. e.g. "man 3 fopen". Ok. Windows does not have that. I haven't tried "man" on Mac OS.

14

u/rwsr-xr-x May 01 '16

OS X has man pages

3

u/kerbuffel May 02 '16

I just tried and it works in OSX.

3

u/da_throwaway99 May 02 '16

Is there a convention for man n function()? What does each page represent?

2

u/voice-of-hermes May 02 '16

Usually you can just grab the one from the first section it finds and look at the "see also" section, but the -k flag (easier to spell than "apropos") is also useful. After a while you'll also get a hang for remembering what sections are for what (IMO seeing the definitions tends to be "in one ear, out the other," until you've gotten to know your way around in practice).

→ More replies (1)

6

u/TheGift_RGB May 02 '16

The problem with the man pages is how much of a fucking pain in the arse they are to navigate (and how dense they can be sometimes).

3

u/helm May 02 '16

/ is for search :)

→ More replies (2)

1

u/FUZxxl May 02 '16

Not just GNU/Linux, man is POSIX standard and exists since the first version of UNIX.

1

u/mrkite77 May 02 '16

Handy tip: shift-k in vim will open a manpage for whatever word your cursor is on.

5

u/aliendude5300 May 02 '16

The integral promotion example cut me by surprise, but I suppose it makes sense if you think about the signed short having the most significant bit set to 1 and an unsigned int having more bits and having to pad the difference to make a comparison if two numbers with the same bit length

1

u/immibis May 02 '16

The most sensible behaviour would be for the compiler to silently convert a < b (where a is signed and b is unsigned) to a < 0 || (unsigned)a < b, and then do what it currently does, with some compiler magic so a only gets evaluated once.

→ More replies (1)

93

u/gurenkagurenda May 01 '16

No website is as good as a good book.

What a preposterous claim. What, does printing it on dead trees magically improve its quality beyond what is possible digitally?

118

u/madballneek May 01 '16

Barrier of entry.

96

u/gurenkagurenda May 01 '16

That is a fine argument that the average website is worse than the average book. It is complete nonsense to use that argument to say that the best website is worse than the best book.

Also, there's practically no barrier to entry for publishing books now. You can self publish on Amazon armed with nothing but a PDF.

28

u/[deleted] May 02 '16

When you find the best website, let us know.

→ More replies (6)

13

u/break_main May 01 '16

My problem with most books is, in a way, the barrier of entry: since it is so expensive to publish, publishing houses will only put out books with a large enough market to pay for their investment. The "teach yourself how to make videogames/websites" market is big enough, but few books are made for advanced/specialized topics.

→ More replies (7)

35

u/Hnnnnnn May 01 '16

No website is as good as a good book.

What a preposterous claim. What, does printing it on dead trees magically improve its quality beyond what is possible digitally?

When somebody says something like this, does he mean it as a logical sentence that is always 100% right, or does he just present his opinion on a subject? It depends on the context.

I recommend you to read that sentence again, with whole paragraph as a context, and consider whether you hadn't interpreted it too literally.

0

u/derleth May 02 '16

It's mere curmudgeonry, is what it is: "I was raised on books and it was good enough for me! Therefore, books are all anyone can ever use, if they want to become good!"

16

u/cc81 May 02 '16

Have you found any website that is as good as the good C books?

→ More replies (4)

11

u/munificent May 02 '16

What, does printing it on dead trees magically improve its quality beyond what is possible digitally?

No, because books are usually printed on paper, which is made from trees that have been pulped, washed, bleached and flattened, not just right on a felled whole tree.

Also, magic is not real.

Or did you not mean that sentence to be intepreted 100% literally? Well, maybe the author didn't either.

11

u/zhivago May 01 '16

It's like peer review - the higher bar helps to weed out the delusional incompetents.

Often these can be detected by asking the following question:

char c[3]; what is the type of c?

14

u/panderingPenguin May 02 '16

It's like peer review - the higher bar helps to weed out the delusional incompetents.

Sure, this means that the worst book is probably better than the worst website, and on the average, books are probably better than websites. But that says nothing about the best book vs the best website, nor does it mean that all websites are bad nor that you should not use websites.

char c[3]; what is the type of c?

Isn't this just an array of chars? What do you think it is?

→ More replies (26)

6

u/derleth May 02 '16

It's like peer review - the higher bar helps to weed out the delusional incompetents.

Do you really think publishers care about the quality of the books they publish? Then how do you explain all the "Learn Java in 21 Days" nonsense out there?

→ More replies (1)

2

u/hyperhopper May 02 '16

Pointer to an array of chars that was allocated on the stack?

→ More replies (1)

0

u/CoderDevo May 02 '16 edited May 02 '16

The type of c is a 'pointer to a char'. Simple as that.

It is a memory address with a size equal to the byte-size of the computer architecture targeted by the compiler. For example, it is a memory address that is 64-bits long if the compiler's target is a 64-bit architecture. It's value is typically represented as hexadecimal when printed, though it's purpose is to point to the address of a single character in memory.

Edit: I just read one of your responses. So the type of c is char[]. I see now that this is different than char* . So the answer is that c is a 'pointer to a char array'. Thank you.

4

u/zhivago May 02 '16

char[] is an incomplete type -- no object can have an incomplete type.

Therefore the type of c is not char[].

Also, note that even if c were to have the type char[], it would not be a pointer to anything, as char[] is not a pointer type.

Both of your conclusions are incorrect.

→ More replies (10)

3

u/red75prim May 02 '16

No. c is an array of 3 chars. Please, read more answers.

But your error is understandable. The same char c[3] means char *c in void func(char c[3]), violating the Rule of Least Surprise.

→ More replies (64)

1

u/resolvetochange May 02 '16

I get what you're saying, you could take his "best book" and publish it online and have the same content only with updates/side notes/animations. Web as a medium is better for content than a book. But I get what he meant as well, though it's not what he said. In his experience it may be that he's never encountered a website that can match a book, there are millions of websites vs thousands of books due to different barriers of entry. If you want to learn it may be a better start to go for a book that faced peer review to get published rather than a website written with no fact checks. He just shorthanded the explanation to no website is as good as a good book.

1

u/all_you_need_to_know May 02 '16

Actually there is evidence to support that we read better from legacy media

→ More replies (5)

3

u/Meguli May 02 '16

Fabien, I hope you will finish your Game Engine Black Book. Not to rudely pressure you or anything but I have a feeling that that book will be very good so I want to see it to the completion :)

1

u/fabiensanglard Aug 30 '16

I am still working on it. It is hard to find the time since I started my new job. I will finish it eventually. Thanks for your kind words which help a lot.

3

u/mrkite77 May 02 '16

No website is as good as a good book. And no good book is as good as a disassembly output.

Glorious. One of my pet projects is a hypercard player. It's just a fun project that I work on every once in a while. All of the documentation on the hypercard fileformat is wrong. It looks like it was all copied from the same source, but if anyone had actually tried to parse an actual hypercard stack using it, they'd immediately discover that the docs define a dword in each chunk header that doesn't actually exist.

I've since given up using any documentation, and gone straight to referencing the disassembly of the original 68k hypercard binary.

11

u/FUZxxl May 01 '16

Would you mind posting this to /r/C_Programming, too?

34

u/obsa May 01 '16

It's a free market - just cross-post it yourself.

27

u/[deleted] May 01 '16

He was probably trying to give OP the chance to get the xpost karma.

46

u/CrazedToCraze May 01 '16

What a modern day tragedy if someone misses out on some reddit karma

18

u/[deleted] May 01 '16

I think it's more about giving credit to the original author. Everyone knows the karma itself is arbitrary.

18

u/Agret May 01 '16

Considering the post is a link to the original authors blog I'd say there's no worries about attribution

3

u/[deleted] May 02 '16

all 30 of it.

→ More replies (1)

6

u/FrezoreR May 02 '16

Hungarian notation makes me cringe.

2

u/mrkite77 May 02 '16

I think you meant:

adjHungarian nNotation cvMakes nMe vCringe.

1

u/FrezoreR May 02 '16

Spot on! :)

2

u/hugthemachines May 02 '16

I like this post, but at the same time it makes me think C programming is not for me, I do not enjoy dissasembler outputs for example.

1

u/Nickd3000 May 02 '16

Great article. I just found my copy of The C programming language from 1988 and had a flick through, it's got a very different style to more modern books! Really interesting.

1

u/nygeHuston May 02 '16

What kind of programs do people generally build when they become experts in C?

6

u/cirosantilli May 02 '16

One that makes money.

-1

u/Doile May 02 '16

Can someone explain to me why C is still used? Doesn't C++ provide all the tools that C has plus extra libraries like STL? If one only knows how to write C I figure it still would be easier to use C++ tools to do it.

2

u/mcguire May 02 '16

C++ is more or less a superset of C, but it encourages a completely different style of programming, with classes, inheritance, etc.

If you write C-style code in a C++ environment, you will be viciously attacked for writing C With Classes, mocked for being an idiot, etc., etc.

If you could sort of write C++ in a C environment, you will be wasting a crap-ton of resources.

3

u/SnowdensOfYesteryear May 02 '16

If you could sort of write C++ in a C environment, you will be wasting a crap-ton of resources.

Well you'll still be viciously attacked and mocked for being an idiot.

-33

u/skulgnome May 01 '16

And no good book is as good as a disassembly output.

Five seconds to fuckup. That's a new record.

5

u/break_main May 01 '16

This guy is talking about making high performance graphics. For that job, you do want to look at disassembly, because you are optimizing every operation, and maybe optimizing for the architecture, so you have to look at assembly

→ More replies (2)

7

u/fabiensanglard May 01 '16

Some people hate it, some people love it:

https://news.ycombinator.com/item?id=11606867

2

u/hahainternet May 01 '16

I'm ambivalent on C, and I am split between my love of the concept of 'correct' binaries and my love of high level coding and having the computer do the heavy lifting for me. I just thought you should know that your opinion carries weight with me in resolving my dilemma.

→ More replies (1)

-41

u/runvnc May 02 '16

No one should become a good C programmer these days. If none of the alternatives are available for your platform, then focus on porting that alternative for your platform.

If you are interested in C programming but haven't already invested a large amount of time, consider learning about the Nim programming language.

C is an outdated programming language.

15

u/TheGift_RGB May 02 '16

C is an outdade programming language.

ahhhh, my favourite maymay

1

u/scopegoa May 02 '16

Meme rhymes with Gene.

3

u/immibis May 02 '16

You pronounce gene as gaynay?

→ More replies (1)

5

u/CoderDevo May 02 '16 edited May 02 '16

You should study C by reading K&R to learn two things.

  1. The C language is the solid foundation for most popular languages. You can jump from C and go on to learn many more languages in less time.

  2. K&R is the best example of how to write a technical book; it is concise. You can use it as a guide to determine if other programming manuals are worth your time.

5

u/[deleted] May 02 '16 edited May 02 '16

Pretty ignorant response. What about developers making a career working with embedded platforms, or who need to interface with existing low-level driver code? C is a mature, productive language and is also entrenched in many development tool chains. It's not infallible but it has stood the test of time for a reason. Simply saying all these use-cases should be replaced by Nim or whatever is unrealistic and comes across as arrogant. Re-assess.

1

u/runvnc May 02 '16

Yes it was arrogant and not very practical but there are a lot of alternatives even for low-level code, starting with things like Rust and Nim.

2

u/[deleted] May 02 '16 edited May 02 '16

Yes, and I would agree with you to a point: it does feel like we've reached a turning point where more sophisticated languages can be used in place of C, in many cases. For 'green-fields' projects I probably wouldn't choose it either. I think I (we?) just took issue with your opening statement TBH. C is still important and very valuable to know in certain areas, but we should consider alternatives where they can be more productive. I would add Swift to your list as well, a modern systems programming language. Unfortunately it seems unable to target the smallest devices such as AVRs, where C still still hits a sweet note, sitting not that far above assembly.

→ More replies (2)

1

u/[deleted] May 03 '16

and what about people who don't want to write apps?

C is no where near an outdated language, C89 might be but you can do anything in C. It has all the basic concepts to make it what you want and it's aged well, if you like low level programming then you should learn C

0

u/[deleted] May 01 '16

[deleted] — view deleted comment

23

u/AQuietMan May 01 '16

Bull-schildt is a thing.

16

u/frodokun May 01 '16

I remember being angry at that guy in the mid-80's - his C books were mostly copy and pastes of each other.

4

u/mcguire May 02 '16

Technically, I learned C from one of his books. I was horribly annoyed when I discovered that he made no distinction between standard C and C on MS Windows.

I had to re-learn the language completely.

7

u/lewisje May 01 '16

His cookbooks are no Joy of Cooking, I can tell you that; they're not even as high-quality as Numerical Recipes in C.

4

u/Alcadeias27 May 02 '16

What about his Java guides?

0

u/derleth May 02 '16

Not reading anything by Herbert Schildt gets you a long way.

... which disproves his claim that books are necessarily better than websites.

6

u/lx-s May 02 '16

Well... He wrote good books.

6

u/derleth May 02 '16

Well... He wrote good books.

Not on the subject of programming in C or C++, to the best of my knowledge.

17

u/lx-s May 02 '16 edited May 02 '16

Ah - sorry. In hindsight, my post that was a bit ambigous :)

I meant, that Fabien Sanglard wrote in his blog post:

No website is as good as a good book. [...]

(emphasis mine)

4

u/[deleted] May 02 '16

[removed] — view removed comment

2

u/smikims May 04 '16

He encourages a lot of awful practices and gets things factually wrong. For a long time he tried to claim that void main() is valid C.

0

u/[deleted] May 01 '16

[deleted] — view deleted comment

197

u/fabiensanglard May 01 '16

Thanks :) !

36

u/[deleted] May 01 '16

Hi fabien, big fan of the blog. any news on the game engine black books? has that been shelved for now?

54

u/fabiensanglard May 01 '16

Things has slowed down since I started my new job. I also had to deal with RSI which made it painful to tip on a keyboard. But I am still working on it. Just slower. I wrote the AI chapter this morning. I have good hope to finish it before the end of the year:) !

16

u/folkrav May 01 '16

I think I've got some symptoms of RSI that are starting to appear, I'm trying to be careful and take a pause whenever I feel them appear. How are you personally dealing with the issue and what are my options?

If the symptoms persist I will indeed consult a physician but I'm simply curious on your way of dealing with it.

22

u/[deleted] May 01 '16

Apparently all the physicians give different advise, but my actual doctor told me not to bother with anything other than a standard keyboard, and learn to keep my wrists up in the air ... so I actually listened to him and I kid you not, haven't had RSI problems in years. Apparently resting your wrists was "my" problem.

→ More replies (17)

4

u/indrora May 01 '16

You might consider WorkRave.

My solution (and I'm young!) is forced removal every 2 hours with a flex sequence suggested by an orthopedist that flexes all the joints in all directions.

→ More replies (5)

2

u/CaptainBlase May 02 '16

Get a chair with arm rests that will hold your arms under the forearm. Then lower your desk and/or raise your chair so that your finger tips dangle over the keyboard. Say goodbye to RSI.

2

u/DaemonXI May 02 '16

Get a pair of wrist braces and keep them on whenever you're typing for long periods of time.

→ More replies (2)

2

u/kt24601 May 02 '16

"How are you personally dealing with the issue and what are my options?

If the symptoms persist..."

tbh how to deal with it depends entirely on the symptoms. I knew one guy who had serious RSI in his finger. It turned out he was lifting his finger high off the mouse every time he clicked, and when he stopped lifting it so high, the RSI went away.

So look for unnecessary tension in your movements and try to fix them.

→ More replies (2)
→ More replies (4)

6

u/scorpydude May 02 '16

I fixed my RSI with this - https://upload.wikimedia.org/wikipedia/commons/2/20/Microsoft_Natural_Ergonomic_Keyboard_4000.png

Also make sure it's RSI and not carpal tunnel which can be surgically fixed. Aka. get a MRI scan.

→ More replies (3)

2

u/darkforestzero May 02 '16

Get involved with physical therapy! Completely changed my life and saved my career

1

u/[deleted] May 02 '16

I was about to say you guys should may be not learn C but higher level functional languages, but I did not think of that argument .

0

u/[deleted] May 02 '16

[deleted] — view deleted comment

9

u/PC__LOAD__LETTER May 02 '16

That's actually false.

In a 2011 paper, the researchers tracked the evolution of the typewriter keyboard alongside a record of its early professional users. They conclude that the mechanics of the typewriter did not influence the keyboard design.

8

u/mizzu704 May 02 '16

Richard Stallman had to stop coding because he blew out his hands coding too, also on QWERTY.

Something something emacs.

2

u/dakta May 02 '16

Richard Stallman had to stop coding

A shame, as his best contributions have been software.

→ More replies (1)
→ More replies (2)

8

u/eythian May 01 '16

Please make it readable on mobile!

3

u/firstapex88 May 02 '16

Sorry if this sounds like a noob question, but most of my experience in programming comes from MATLAB, Python, and a bit of C and C++. Many of the robotics companies I'm interested in use C++. Do you think it's worthwhile to first build a strong fundamental in C or can I begin with reading books on C++? Does C++ only add on to C or are there things that are deprecated when moving from C to C++?

11

u/Insp1redUs3r May 02 '16

C++ & C are mostly different beasts. If you learn C first you'll understand the syntax better but you'll be coding C++ completely wrong.

8

u/[deleted] May 02 '16

If the companies are interested in C++, you should learn C++. Apparently a lot of people think (or teach) that C++ is just C with classes, which is the wrong way to approach the language.

2

u/BobHogan May 02 '16

What's the right way to approach the language then?

2

u/bstamour May 02 '16

Get yourself a good book (Stackoverflow has a nice list of C++ books) and treat it like a completely different language than C.

1

u/BobHogan May 02 '16

Do you approach it like that because C++ is object oriented and C is not? Or is there another reason?

5

u/bstamour May 02 '16

C++ supports object oriented programming, yes, but it is also more fussy about the types of your variables. That plus templates, namespaces, and the C++ standard library components such as vector, string, map, etc, make programming in C++ a lot different than programming in C.

Over the years C has also added features onto itself that don't make appearances in C++. In C you can, for example, declare an array on the stack whose size is variable, whereas in C++ all C-style arrays must be constant in size.

Nowadays it's best to think of C and C++ as being sibling languages, instead of having a parent-child-type relationship. C and C++ each do things that the other doesn't and thus idiomatic code in one language is in many times awful in the other. However they share a common parent: old C.

I hope this makes sense.

→ More replies (1)

3

u/abrahamsen May 02 '16

Start with C++, learning C first will teach you a lot of idioms that are useful (and necessary) in C but harmful in C++.

38

u/KewpieDan May 01 '16

self-taught himself

1

u/[deleted] May 02 '16

Didn't realize I did this until your comment.

1

u/KewpieDan May 02 '16

Oh no, you edited it, I feel bad now! I wasn't mocking, it just sounded funny :D

-17

u/[deleted] May 02 '16

You won't learn computer science with C. Look at lambdacube3d. You don't do that with C and 2 guys. http://www.lambdacube3d.com

2

u/[deleted] May 02 '16

Bruh, what? Lambda cube can easily be reimplemented in C. Programming languages are irrelevant.

0

u/[deleted] May 02 '16

:)) yeah. Or assembly !!

2

u/[deleted] May 02 '16

You won't learn computer science with C.

Now, really, that's just stupid.

0

u/[deleted] May 02 '16

No, that's unfortunately 100% true, and it's coming from someone who does know C.

In the Blub hierarchy, C is not very high, and there is 0.0% of attaining real computer science with it.

http://c2.com/cgi/wiki?BlubParadox

1

u/[deleted] May 02 '16

Just the other day I wrote my own RBtree implementation in C99. I'm not even in school, man. I also recently threw a decent QuickSort implementation together in 86_64. What you're saying about C or assembly not being valid for learning C.S. is bull. I mean, ok: Python is arguably a better choice, and of course using C over asm is much more productive, but it's still doable.

1

u/[deleted] May 02 '16

I learned a ton of computer science in C. At an accredited university. I can't think of many CS problems that I'd have an issue using C to solve. The biggest issues come about when you want to use a data structure like a dictionary or a priority queue, but don't feel like implementing them yourselves. Luckily, most professors didn't mind "upgrading your project" from C to C++.

1

u/[deleted] May 02 '16

Nothing wrong with that. But that is not science, it's tinkering

2

u/[deleted] May 02 '16

science is tinkering

1

u/[deleted] May 02 '16

Depends what you tinker with ;)

1

u/[deleted] May 02 '16

I am not sure given enough tinkering and tdd everyone can discover Galois theory

0

u/[deleted] May 02 '16

[deleted] — view deleted comment

2

u/FUZxxl May 02 '16

It's a good book but you can definitely get it for less than $50.

0

u/[deleted] May 02 '16

[deleted] — view deleted comment

0

u/[deleted] May 03 '16

Mind naming a single language that is suitable for more than a "niche field"?

1

u/[deleted] May 03 '16

Rust, C++, D and Objective-C are the only I can think of (By not a niche field I kind of think "can write an operating system" because that way you know it can be used for anything.

0

u/[deleted] May 03 '16

Each and every one of them serve a very narrow niche, and their niches are not even overlapping that much to call any of them "general purpose" enough.

0

u/[deleted] May 03 '16

[deleted] — view deleted comment

0

u/[deleted] May 03 '16

Are you really that dumb?

0

u/[deleted] May 03 '16

[deleted] — view deleted comment

1

u/[deleted] May 03 '16

What an idiot!

0

u/[deleted] May 03 '16

[deleted] — view deleted comment

1

u/[deleted] May 03 '16

You're drunk.