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

C Programming Languages

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 90
Thread images: 8

File: image.png (150KB, 2000x2810px) Image search: [Google]
image.png
150KB, 2000x2810px
What is the best programming language and why is it C?

I'll start:
>your favorite functional meme language interpreter and VM are implemented in C
>>
>>56276692
It's not 1989 anymore grandpa, we're C++17 now.
>>
>>56276692
I bet you don't even know assembly do you?
>>
>>56276692
I know some of C++ and I can tell you that:
> You can create a high level interface and work on it and work at low level at the same time.
> Support multithreading
> It's multiparadigm (OOP && Generic Programming)
>>
>>56276715
>>56276871
Have you tried C++++? It's even better than c++
>>
>>56276692
>best programming language
only kids who don't know shit about programming would ever say that.
>>
>>56276802
FUCK YOU SHITFUCKER I FUCK YOU I HAVE PHD FROM IIT BOMBAY IN C PROGRAMMING
>>
>>56276925
You'r right...
>>
File: image.gif (1MB, 280x200px) Image search: [Google]
image.gif
1MB, 280x200px
>>56276715
>>56276871
>>56276881
>mfw C++ returns C before incrementing
>>
I hope you mean C11?
C++17 is still better better because of its move semantics. Somebody shoul write C++, the good parts.

However there is Rust and its even better because today it got rid of its drop flags in its nightly(see Reddit).
That means once it gets untagged unions C can slowly retire. What a time to be alive, i thought it would never happen.
>>
>>56277099
>That means once it gets xyz C can slowly retire
people have been saying that shit for years now, but every language failed at replacing C, and most likely will fail for the next 20 years
>>
>>56277177
Most C users would consider most C novices a security risk. Not C interfaces to hardware mind you,
C users that start at writing C code, at least for their first decade.

C interfaces as a common denominator likely will never go away, although lifetime and borrowchecking semantics are certainly needed here mid-term.
Although standardizing a common c documentation format for this would maybe enough.

Kernels most likely will go the microkernel way and leave most hardware to userspace deamons or applications directly, because its more efficient, needs fewer reboots and causes less interupts.
There really is no need to maintain a giant C codebase anymore in a few years. Sure that doesn't mean C will go away, you will 20 find linux kernels everywhere even in 20 years.

But its just not something you should start a new project on if rust and c++ continue to improve. (finally we already waited 20 years for this mind you and you can probably find a job writing C until you retire.)
>>
>>56276692
> C
> because you don't have to memorize a massive bunch of libraries, you just learn to write code and then program whatever you need. and it runs fast.
>>
>>56278779
What do you mean? Do you not import open source libraries?
>>
>>56277024
perfect for counting in loops my dude
>>
>>56277376
>if rust and c++ continue to improve
still a hypothetical, it has never happened before, what makes you think it ever will
c will always be the king of its niche
>>
>>56276802
Actually, that's funny to remember, that when UNIX got moved from ASM to C, it's binary size increased 1,5 times.
>>
Hey /g/ i started learning programming as a hobby. I tried python and java, but i quickly got bored of them. Now i started with c++ and it looks good so far. I want to make multiplatform programs and c++ with qt is very nice to use. Do you think it's worth it or am i just wasting my time? Also why would i use c or rust? As in, what can i make with them? Drivers and kernel modules look interesting, but i'd prefer to make something useful. Should i consider learning c instead of c++? If so, why? Thanks.
>>
>>56278941
I reinvent the wheel every time.
>>
>>56279250
In the current year, unless you are working on low-level kernel/hypervisor code or legacy embedded systems, you really should be using a higher level language than C.
>>
File: 1471537085096.png (7KB, 220x165px) Image search: [Google]
1471537085096.png
7KB, 220x165px
>>56276692

#include <string>
#include <vector>
#include <iostream>

std::vector<std::string> implements {"anvils", "tweezers", "the pelvis of a dead dog", "a used burlap sack"};
while (true)
{
for (const auto &e : implements)
{
std::cout << "Go fuck yourself with " << e << "!\n";
}
}
>>
File: 1470869490388.jpg (27KB, 460x503px) Image search: [Google]
1470869490388.jpg
27KB, 460x503px
>>56276692
>I really enjoy writing code in a language used in the last century that can crash from printing out some strings.... but do it quite quickly!
>>
>>56280969
>I'm a bad programmer, therefore it's a bad language!
>>
>>56280885
You forgot to define a main() function, and your indentation is horrible.

Also:
#include <string>
#include <vector>
#include <iostream>

int main() {
std::vector<std::string> implements {"anvils",
"tweezers",
"the pelvis of a dead dog",
"a used burlap sack"};
while (true) {
for (const auto &e : implements) {
std::cout << "Go fuck yourself with " << e << "!\n";
}
}
}

661 KiB binary, 11 seconds to compile, 337 byte source

#include <stdio.h>

int main(void) {
char * implements[4] = {"anvils",
"tweezers",
"the pelvis of a dead dog",
"a used burlap sack"};
int i = 0;
while (1) {
printf("Go fuck yourself with %s !\n", implements[i]);
i++;
i = i % 4;
}
}

6 seconds to compile, 16 KiB binary, 298 byte source
>>
>>56281294
>I use a language I learned at university in the 1980s and I haven't moved on because objects, standard libraries that increase productivity and code stability, lambdas and multicore processors don't exist...
>>
>>56281446
>I think it's perfectly acceptable to create a Hello World program that takes up more than half a megabyte of disk space
>>
>>56281434
int i = 0;
while (1) {
printf("%d \n", i)
i++;
i = i % 4;
}

wtf?
doesn't this generate the following sequence
i=0,3,0,3,0,3...

am I just retarded?
>>
>>56281694
Nope, it's an infinite loop, i starts at 0, each time it goes through the loop it increments by 1, but the mod statement means that when it reaches 4, it resets to 0. So it goes 0,1,2,3,0,1,2,3,0,1,2,3...
>>
>>56281694
Jesus wept
>>
Why do people who worship C always post examples of trivial programs like FizzBuzz and Hello World? Do they ever write anything of significance?
>>
#include <stdlib.h>
#include <unistd.h>

int main()
{
while(1)
fork();
}
>>
>>56280241

> still rocking those carved stone wheels
>>
>>56282485
>stdlib
>>
>>56281593
Here's a challenge for you. Write a program in C that will go to a 4chan thread and print out the top 5 posts with the most number of replies.
>>
>>56282627
I'd never use C for a task like that. I'd probably learn Python and use that.

Right tools for the job and all that shit.
>>
>>56282648
So C is only useful for generating small hello world binaries?
>>
>>56282652
C is useful for optimized low level stuff.

Using it for menial tasks like that is crazy and overly complicated.
>>
File: BYdOKxo.png (399KB, 1419x726px) Image search: [Google]
BYdOKxo.png
399KB, 1419x726px
>>56276692
>>
>>56282658
As for what optimized low level stuff means, just look at what OP said.

It's perfect for that.
>>
>>56277376
>microkernel
>more efficient
dumb
>>
>>56282694
So you spend most of your time writing VMs and kernels? You must be one 1337 hacker.
>>
>>56282728
No, although I'd like to experiment with microcontrollers one of those days, and that's why I'm learning C.
>>
>>56280302
Wrong.

C++ mangles function names in the debug symbols, making debugging annoying. If you don't need the C++ abstractions (hint: you never do), just use C as its a simpler language. Simpler to read, simpler to understand, and a simpler language means you can better trust the compiler to work correctly.

Source: I'm a firmware developer at a very large computer hardware company.
>>
>>56282741
And you're proclaiming that a language that you are "learning" is the best?
>>
>>56282762
Let me guess, are you gonna start educating me about how lisp is wonderful and how it should be applied to everything?
>>
>>56282771
No. I just find it strange that someone who barely knows how to write a FizzBuzz in the language is going around claiming that it is the best out there.
>>
>>56282771
Anyway, we're always learning.
>>
>>56281446
>because objects
Sometimes it seems like people don't realize how much of a crutch and a waste objects can be.

I had a guy at work tell me that, for a data task that didn't need any objects at all, creating thousands of ruby objects wasn't slowing it down. He wanted the objects so that he could concatenate first and last names with a ruby method. Fucking ruby programmers.
>>
>>56276692
The best language is literally every Lisp derivative, with the possible exception of Clojure
But even Clojure is better than C

I'm not saying C is bad
But Lisp...
You will never beat it
>>
>>56282808
fucking lispfags
>>
>>56282761
Out of curiosity, when you're writing C, do you use C++ to test it? I've found some sensible-sounding advice that says that's the way to go, but it seems really counterintuitive.
>>
>>56282794
>Yeah who needs encapsulation and type safety checks! Just use strcat! Who cares if we write past the end of the allocated space!
>>
>>56282825
What do you mean test it? We write the code, run the debugger, step through it and make sure the hardware is doing its thing, then release an image to the validation team and they run all sorts of automated tests on the hardware and try to catch bugs in the hardware design or the firmware.
>>
>>56282112
Most non-trivial programs in any language are too big to be reasonably posted on 4chan, it's better to just link to github or something. Especially since C development practices usually involve multiple files. And anything with GUIs or the like is non-portable, little point in posting the source to demonstrate a point.

>>56282627
>>56282648
Is there a library in either of those languages that gives you access to the 4chan API? Otherwise I'd have to resort to copy-pasting the whole thread into a text file and parsing it. Parsing data and doing calculations isn't hard, getting the data off the internet in the first place is.

>>56282652
It's used for a lot of low-level programming, most Unix operating systems are written in C, as are the standard programs that come with them. It's also a popular IR for compilers - a lot of people writing a compiler for a new language would rather parse a source file in the new language, compile it to a subset of C, and call a C compiler on that, rather than write the whole backend themselves. It's also fairly popular for games and stuff where performance is important - though it's partially been superseded by C++, and a lot of "game programming" is really just doing scripting in some other language for game engines written in C.

>>56282677
What is the intended connotation of this?

>>56282728
Anyone who wants to do any sort of low-level stuff like that should have some knowledge of C, even if it's not their preferred language. Even high level languages like Java and Python require a runtime environment written in something like C or assembly. So if you're going to be writing purely userland applications, C might not be that important, but if you write compilers, device drivers, embedded systems stuff, or just anything where speed is a priority, that's where C is useful.
>>
>>56282894
You can use popen and wget.
>>
>>56282815
I can't hear you over all this clean fucking code
>>
>>56282943
>I can't hear you over this overhead
ftfy
>>
>>56282761
>If you don't need the C++ abstractions (hint: you never do)
If you're writing code that lends itself naturally to the OOP approach, C++ classes can be beneficial, OOP in C is pretty annoying. Although Java seems better for OOP anyway, C++ tries too hard to be a do-everything language.

>>56282844
Any high-level language that protects you from buffer overflows was initially implemented in something low-level like C or assembly. Which means that it is possible to do safe string handling in a language like C, it's just a lot of work to implement it the first time.

Besides, their argument wasn't that you should use C for string-heavy tasks, rather it was that people shouldn't use OOP unless the situation actually calls for it.
>>
>>56282949
Modern machines have no trouble running a lisp interpreter, if it tickles your autism that badly you can precompile
>>
File: danielle.png (308KB, 1419x730px) Image search: [Google]
danielle.png
308KB, 1419x730px
>>56282894
>What is the intended connotation of this?
>>
>>56282845
Stuff like this: https://pragprog.com/book/jgade/test-driven-development-for-embedded-c

If I recall descriptions other people have given for this book correctly, it teaches you to write tests in C++ to test your C code. I don't know if TDD is considered meme-tier to C programmers. Parts of the description to that book sound nice, others sound like marketing-bait:

> With his years of training, coaching, and practicing TDD in C, C++, Java, and C# he will lead you from being a novice in TDD...

Shit like that makes me think he might not know what the fuck he's talking about, and he's just treating everything like a nail because he has a hammer. Would rather hear from somebody who uses C at his job.
>>
>>56282959
In most languages strings are objects. Doing operations with strings is simple because they have predefined methods that encapsulate all the details. Nobody wants to fucking mess around with char*'s and constantly checking bounds.
>>
>>56276715
Let's just keep tacking even more shit and it'll be even better!

No. C++ is great for specializing in a certain field, but it's too complicated for anyone (or at least most people) to completely master and understand.

Whereas C is great (some would say perfect) because it's simple and elegant. It took the complexity of assembly and abstracted/generalized it to run anywhere and be readable by most people with minimal learning. It's the backbone and/or basis of all major languages to date, and it remains among the top used languages. No language has ever been as successful and revolutionary in its goals.

C++ is just a C library/extension that got out of hand such that it needed a different compiler and standard.
>>
File: 1451188777350.jpg (75KB, 576x717px) Image search: [Google]
1451188777350.jpg
75KB, 576x717px
>tfw STILL have no idea how the fuck pointers work
>>
>>56282963
you mean including the lisp runtime in my program which forces me to license my program as whatever the interpreter was licensed as?

let's face it, lisp is trash for anything but CS masturbation
>>56283050
>be readable by most people with minimal learning.
if only that were true

the truth is no one knows how to program so it results in unreadable messes
>>
>>56283057
Points are a reference to a point in memory, they are like a variable but do not initialize memory or store anything.
>>
>>56282844
This wasn't a C or ruby problem - it was meant to highlight how much people rely on objects when they shouldn't. More specifically, we were looking at a slow running report that was written with rails, and he wanted to continue to make objects out of what was returned from the ORM to get string concatenation, instead of having the database take care of that because rails programmers are all afraid of the big bad database man.

DHH, an author of, and very outspoken advocate for rails literally has this to say about databases:

>I don’t want my database to be clever!
>I consider stored procedures and constraints vile and reckless destroyers of coherence.
>No, Mr. Database, you can not have my business logic.
>Your procedural ambitions will bear no fruit and you’ll have to pry that logic from my dead, cold object-oriented hands...
>I want a single layer of cleverness: My domain model.

And so rails developers shy away from the thought of trusting a database to do anything.
>>
>>56283066
>the truth is no one knows how to program so it results in unreadable messes
Fair enough, but you have to admit that C code is less complex than C++ code in general. There's literally less syntax to cope with.
>>
>>56283099
Oh yes, C++ is simply unreadable for me.

C I can eventually understand if I focus hard enough.
>>
File: amanda.png (426KB, 1419x734px) Image search: [Google]
amanda.png
426KB, 1419x734px
>>
>>56283094
You realize that strings are objects too right?
>>
>>56283075
But what's the use of them? How do they help me?
>>
>>56283137
What if you need two variables to match in value?

Normally you would create another variable with an identical value but now you have taken twice the space for the same amount of information.

If you created a pointer to the first variable you get the same result with less resources and the pointer is dynamically updated as well, no need to update the second variable to the new value each time.
>>
>>56283137
In C they are the only way of dealing with data that is unknown size at compile time. They are also the foundation of arrays and strings (though these can be done better with a fairly simple library).

In sepples they are as good as redundant unless you're doing genuinely low level code. If you really need a pointer you can also just use unique_ptr which is a lot easier.
>>
>>56283137
Pointers are what every variable is under the hood. They basically give you more control over the program at a lower level, meaning more efficiency and/or simplicity in a program.
>>
>>56283162
So in this scenario, it's just optimization?
>>56283166
And in this one it's just to prevent some kind of overflow?
>>
>>56283184
>And in this one it's just to prevent some kind of overflow?
Yes and no.

Imagine you're writing a plain text editor. You decide to store all the text in a buffer so you do:
#define SIZE 256000
char text[SIZE];


the question is what do you set size to? No matter what you do there's always the possible of a bigger text file being used. The problem is you just can't pick a size at compile time that you know will be big enough (and reserving large chunks of memory is pant-on-head retarded anyway).

Pointers let you grow the buffer as it's used. So when it fills up you can just reserve more memory.
>>
>>56283057
A pointer is like a link on a webpage, or a shortcut to a file on your computer.

So basically, something like
int a = 5;
int * ptr = &a;

mean that ptr holds the ADDRESS in memory of the 'a' variable. (The & means "take the address of this variable). So if you try to printf() the pointer, you'll probably get some big number corresponding to the address, rather then the value 5 itself. But you can DEREFERENCE the pointer with the * operator to get the value stored at the address.

Main use of pointers is to implement pass-by-reference semantics (C is purely pass-by-value language).

So if a function has to MODIFY a struct, it's best to pass it as a pointer, otherwise the function will make a copy of the original, then throw it away when it returns. They're likewise useful for functions operating on very large structs, even if they don't modify it - otherwise they'll have to copy the whole big struct, which can waste a lot of memory.

Additionally, pointers are the way arrays are passed as arguments, if you write a function taking an array as argument, it just converts it to a pointer to the first element, and you can do "pointer arithmetic" to access the other elements.

Although in addition to understanding pointers, you should know there's basically 3 types of memory allocation:

global variables, and static local variables - allocated when program starts, deallocated when program closes, alive for the entire time program is running

non-static local variables: allocated when function is called, deallocated when the function exits
(this means if you call a function, which declares a local variable, and returns a pointer to that variable, you'll have issues if you try to dereference the variable later on, since the variable it points to is deallocated)
>>
>>56276692
Is this pretty much the best book for getting into C?
>>
>>56283246
>>56283324
thank you for the explanations
>>
>>56281694
see >>56281872
It's just there for infinite fuckery
>>
>>56283342
No, the 2nd edition is.

After that you'll probably want to read something else since C evolved since then.
>>
>>56283324
Different anon but thank you very much for the comprehensive explanation
>>
>>56283324
>>56283057
(cont)
finally there's heap memory, which is allocated with malloc() and deallocated with free(). So the programmer is in direct control of this memory. And it's accessible ONLY with pointers, so a call to malloc(20) returns a POINTER to the beginning of a block of 20 bytes on the heap. And you should free() that memory before the pointer goes out of scope, or is pointed to something else (you can reassign pointers just like you can reassign variables), or you'll end up with a "memory leak" (meaning memory is not deallocated and given back to the OS, but is inaccessible to the program; C has no garbage collection).

This may seem like a bunch of confusing nonsense, but probably the best way to get used to pointers is to practice, try solving random problems in pure C, and eventually you'll come across a situation where pointers are the best way of doing it. For example, you pretty much cannot do i/o without pointers, since scanf() requires a pointer as its second argument, because it has to modify memory before returning it. (Though in practice, you'll end up using &var, rather than creating an explicit extra pointer variable). And likewise, if you want to simulate OOP in C, you'll use structs to hold member variables, but structs cannot hold functions, so instead of calling

Object object = new Object


as in C++, you might do something like

struct Object * object = new_object()


where new_object() is a function that malloc's space for a new struct, assigns values to its members, and returns a pointer to it.
>>
>>56279185
well duh c isn't as efficient as asm but it's kinda close and it's way more productive. C isn't my favourite language but that's a dumb comment.
>>
>>56279185
>>56283445
Nothing is going to be as efficient as assembly, the whole point of asm is it's basically a "word for word translation" of machine code, so nothing can ever beat highly optimized assembly code. Assembly is still used in some cases where speed and small binary sizes are of critical importance, but it's very hard to code in, and a compiler can generate shitty assembly far faster than a human can. And on top of that, C is portable, so you don't need to rewrite the whole operating system every time you get a new computer.
>>
>>56279185
>>56283486
>so you don't need to rewrite the whole operating system every time you get a new computer.
this, im pretty sure ken and ritchie did not care at all about efficiency

the entire point of C was to be a "portable assembler", after all
>>
>>56283512
They probably did care about efficiency, having compilers generate at least half-decent machine code was a priority even from the first FORTRAN compiler in the 1950s. And C actually is fairly efficient, since it's about as low-level as you can go while still being a "high level" language.
>>
>>56283549
i still think it was a very secondary goal, at least

they wanted a portable time-sharing operating system, so they made C
>>
>>56283512
>the entire point of C was to be a "portable assembler", after all
No, the point of C was to get a language working on their cheap computer that was less awful than assembler. Portability was mostly an accident.
Thread posts: 90
Thread images: 8


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

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
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.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.