[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
Why the hell C languages need a compiler? I have two months
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: 42
Thread images: 1
File: WHY.jpg (46 KB, 500x375) Image search: [Google]
WHY.jpg
46 KB, 500x375
Why the hell C languages need a compiler?
I have two months of Python and can't understand why they can't just use an interpreter.
>>
But you can: https://github.com/zsaleeba/picoc
>>
>>51250851
Python has a compiler. Check your __pycache__ directory.
>>
They can. It's slower.
>>
Have you considered not being a programmer?
>>
>>51250851
A machine needs machine code.
How do you think the interpreter works? It's interpreted by another iterpreter?
>>
>>51250851
I haven't programmed in years, but what does
count << 

mean?
>>
Because its a real programming language and not for kids like you.
Its for real programmers who actually understand how a cpu works.
You can even use inline asm. Im doing that pretty often to optimize for speed.
>>
>>51250851
Your picture that you posted explains it to you.
>>
>>51250851
>Why the hell C languages need a compiler?

it doesn't?
>>
There is nothing stopping you from interpretting C literally, as the first reply pointed out.
However, compilers do more than just interpret their lines. They also rearrange them, because the compiler knows more about how to speed up program execution than any one programmer.
In addition, it's a lot faster for the computer to just execute machine code than it is to have to interpret what machine code corresponds to your text every time. Developers are not end users, speed is important. Imagine executing a billion commands. That's a billion cycles wasted, assuming you're getting the machine instruction with one cycle (it takes a lot longer). You might be writing small programs now, but you won't be in the future.
There's also more to a toolchain than a compiler. Your toolchain executes preprocessor macros, links libraries, and more.
As you grow as a programmer, you will learn how to deal with the drawbacks of compiled languages versus scripting languages with debugging tools.
>>
>>51250851
If you know the complete programme before you try to do anything with it, there are a lot of extra things you can do: one example is that you can spot code that is unreachable and will never run, and so throw it away.

That's one side of the argument - there are a lot of real advantages like this.

The other side is "because history" - C has always been a compiled language and, since other languages already do the "interpreted" niche better there would be little point in changing it into one as well.
>>
>>51250972
bitwise left shift cout by some arg
>>
>>51250972
It's probably a mistaken cout
>>
>>51250972
Depending on the type of ``count'' and how its ``<<'' operator is overloaded, it could do literally anything
>>
>>51250972
It's a typo, they meant "cout <<" and it represents the standard output
>>
>>51251024
>overloading

disgusting senpai.

don't you sepples fags have interfaces?
>>
You can make an interpreter for C, but there would be no point. A large portion of the speed in C comes from the fact that it is translated into machine code, rather than having another program transform it into machine code at runtime, or directly parsing the syntax at runtime.

Your Python interpreter is written in C. Imagine if that program also had to be interpreted.
>>
Ok, now i get it. But what if i need to read compiled code? The files are unreadable rubbish.
Am i supposed to keep a uncompiled txt file just in the case i want to change something?
>>
>>51251129
>Am i supposed to keep a uncompiled txt file just in the case i want to change something?
yes
>>
>>51251129
wtf?
are you mental lad?

well I guess you could output debug assembly?
>>
>>51250851
HEY GUYS WHY DON'T WE WRITE AN ASSEMBLY INTERPRETER
>>
>>51250851
>using namespace std; for one instance of cout
>allman's style
>count
>space between 'count' and << but no space after <<
>>
Then why did people invent scripting languages in the first place if it doesnt affect the programmer so much i mean his writing and it affects very much the performance of a program?
>>
>>51251129
>Am i supposed to keep a uncompiled txt file just in the case i want to change something?
Yes, that is literally how every programmer programs always.

Why the fuck would you delete your .cpp file after compiling once?
>>
>>51251193
those already exist though.
>>
>>51250851
Suppose that you have a personal woodworker and you want him to build a chair for you. Now, it's easy for you to give him instructions, like "make the legs thinner", or "make the seat so and so", and you can ask him to show you the chair as he progresses. But you could also give him schematics. If you give him schematics, he will know exactly which techniques to use where, and he will be able to do it way faster. The drawbacks are that you can't change your mind in the middle, he'll do it all according to your schematics, and also it's more difficult to understand and draw schematics than it is to simply tell someone what to do when.
>>
>>51251208
They are generally easier to write in, and more forgiving. But they can cause more problems in the long run (im not saying this is always the case).
>>
>>51251129
Are you fucking stupid?
Quit CS
>>
>>51251273
People should program in the oldschoo C-like strict mode only.
I dont know what kind of hipster faggots were alowed to invent scripting languages.
>>
Hahahaha you don't even know how computers work.
>>
>>51251208
>Then why did people invent scripting languages in the first place
So you can distribute and execute source files without the need to either ship platform-specific binaries or require your users to compile your code before executing.

It's just easier and more convenient to work with, and it's used in situations where speed doesn't really matter so much.
>>
>>51251337
I understand that but scripting languages brought some shitty practices with them . For example loose typing... Thats just wrong .
>>
>>51251308
can I show you my Node.js app?
>>
>>51250851
I mostly use Python but I feel like a CSgrad.png is appropriate here.
>>
>>51251364
Dont you fucking dare heretic.
>>
>>51251354
loose typing is fine for the kind of scenarios those languages are preferable. You don't sound like you have the slightest idea what you're talking about.
>>
>>51250978
Kek and rekt
>>
Why is there no logic gate/machine code interpreter??
>>
>>51252484
Kek
>>
>>51250883
They should merge this with python.
I mean having pure C compile to python bytecode then have a very specialized limited set of python objects optimized to work as C primitives types. Then have a library to convert those objects to normal python objects and back. Probably what Cython does but integrated with main Python.
>>
>>51250851
Learn assembly and microcontroller programming.
Then you'll learn how hardware REALLY works, and you'll understand why compilers are needed.
Thread replies: 42
Thread images: 1

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.