JS > C

The absolute state of C

Attached: 20190916120121.png (432x778, 51K)

Other urls found in this thread:

godbolt.org/z/c1nHkc
github.com/andrei-markeev/ts2c
twitter.com/SFWRedditImages

You obviously don't know how key value pairs work.

Attached: 1561597721855.jpg (239x226, 38K)

DEALLOCATE THIS

Your shitty Js JIT engine is written in C/C++

Discover check, and evidently... mate.

This is your brain on C

Attached: 20190916121019.png (136x29, 3K)

yes, yes yes but the C version breaks down to coherent and efficient instructions where as the JS version breaks down to

>HNNNNNNNNGNHNNGNHNG
>KILL MEEE PLZ
>HRGHHGHGHLGHLGHLUUUU
>BLLLLRRTPRPSCHHHHFRSTP
>"ABCDEFGH" == 13 {TRUE}
>MEIN LEBEN

It's the exact opposite. Why do you refuse reality?

Why five printf calls instead of one

C bad it compiles to assembly
i can't read assembly >:(

Why does anyone think this is OK?

>The absolute state of C
*The absolute state of JS to C transpilers

obj = malloc(sizeof(*obj));
obj->key = "hello";
obj->newKey = "test";

Attached: a.jpg (200x300, 46K)

I want you to write a Js program that runs on an ARM cpu, no OS.

You can printf everything in one call, it's just more elegant to write each part separately.

It's 2019, why would I do that? It's the web dev era. I want YOU to write a C program that manipulates the DOM.

Its a transpiler, shouldn't it focus on efficiency

#include

typedef struct {
const char *key;
const char *newKey;
} obj_t;

int main() {
obj_t obj = { "hello" };
obj.newKey = "test";
return 0;
}


nice bait.

>assert
what? why?

this transpiles to the following Javascript:
var obj = {};
(obj = {
})["key"] = [
"h","e",
"l",
"l","o"
].join(''); for
(var k in obj){
obj['newK'+(k.
substr(1,2))]
= obj[k]
}
obj[
"newKey"] =
obj
["newKey"].
substr(0,2)
+"st";
obj["newKey"] = obj
["newKey"].
replace("h","t");

At least I don't poo in the loo rajesh

Attached: B41FF6E3-861C-4CB9-ACF0-78826878AD3D.jpg (480x360, 20K)

>DOM
Web devs are glorified designers

I make my money writing high performance embedded applications.

You mran you DO poo in a loo instead of the street, right?

you're in denial
c-like > all
and if its some snowflake special shit like js or haskell the compiler has to have been programmed in a c-like language or else... you are doomed to being nigger cattle forever
now go back to your inclusive (fag)github repo

Being a designer means we're having a sense of aesthetics. No shave off your neckbeard and change your "funny" code joke shirt, my eyes are bleeding.

That is actually pretty clean code for a transpiler.
Ever tried to look at Cython output? unreadable slow ass garbage describes it best.

>transpiled
>5 printfs instead of 1
>doesn't even generate the correct key : pair code

Transpilers are not supposed to be "clean". They are supposed to be efficient. OP's is horrible.

kill yourself OP and take your shitty transpiler with you.

>transpiling a gc language to one with manual malloc/free calls
lol

What an asbolute bloated and garbage language C is.
Having to malloc() and free() just for to declare string is sheer autism.


Javascript is so precise and elegant, definitely the future of programming.

Attached: 1567974600017.jpg (1367x2048, 385K)

You could make the same argument to promote Rust.

Why can't you just char* it

>Having to manually manage memory in a low level language is sheer autism
This kind of shit is precisely the reason people use C. Do you think memory for strings just comes out of thin air?

Isn't this lacking malloc on both string fields?

They're static strings embedded into the executable, not dynamically created.

No. String literals are statically allocated and are valid for the entire lifetime of the program.

Everything in OP's pic could have been stack/read-only allocated. His transpiler is shit. There's no reason to malloc for simple single function key-value pair, which he did wrong, and print it.

Not exactly, as this is a contrived example which uses string literals stored in read-only memory, not data dynamically allocated on the heap. Also the object magically knows in advance it will only ever have two distinct keys called "key" and "newKey".
The simplest actual implementation of a Javascript object in C would be a hash table with string keys which is able to point to arbitrary data, so you would likely need a struct as value which can store the data type (number, string, boolean or object, assuming you represented null as a NULL pointer) and the value (as another pointer as required).

#include
int main(void) {
printf("{ key: \"hello\", newKey: \"test\" }\n);
return 0;
}

t. 130 IQ.
You could join the MIT

Attached: wojaks_embrace_brainlet.png (1066x600, 252K)

As a possible illustration: JSObject would be a hashtable with wide character strings as keys and pointers to JSValue as values.
Real Javascript engines optimize this by stuffing other kinds of values into invalid floating-point values.
enum JSType {
JSTypeBoolean,
JSTypeNumber,
JSTypeString,
JSTypeObject
};
struct JSValue {
enum JSType type;
union val {
_Bool boolVal;
double numVal;
wchar_t *strVal;
struct JSObject *objVal;
};
};

Efficiency in what way? Does that extra white space really take up that much memory for having readable code (much more important for a transpiler so the humans reading it can know what the fuck is going on)?

You can believe that if you'd like. You're wrong, but you're allowed to believe wrong things. There's a reason why the adults who actually program for things that matter rather than fucking around doing scripting for pornhub use C/C++ or Perl. Memory management is very important if you're doing something memory intensive, and you don't actually "need" to allocate memory for a string, it's just a good habit to keep for when you do need to allocate memory for more serious work later.

The difference is that you need something to run the JS code in, while the C code compiles standalone.

Quit transpiling and grow a brain, mong

did i do something wrong?

Attached: 2019-09-16-15:57:19_598x360_scrot.png (598x360, 22K)

>not retarded
>on Jow Forums
yes, something is wrong

Your colorscheme is kinda wrong

shouldn't it be
obj_t *obj = (obj_t*)malloc(sizeof(obj_t));

also, free() that shit.

imagine being Cnile and talking about "muh speed" when modern computing makes any difference in speed redundant

>typedef

no, also im going to put more pink

>free() that shit.
why? inst it freed when the main function ends?

also whats the point of coding like that? isn't this code denying the compiler the ability to copy data ende not able to optimize?

This

>>free() that shit.
>why? inst it freed when the main function ends?
The absolute state of websh*t (or Java/C#) devs

Attached: ewww.png (557x625, 343K)

It requires multiple function calls which is less efficient, with that being said the actual overhead of the function call will be far lower than that of the actual printf formatting code. It should still be combined into a single printf though, you can then format the code for readability.

The absolute state of neo Jow Forums

>Not fputs
Muh performance

Disprove what I said then, or you can compile the C code then look at the disassembly and see that you're wrong.

godbolt.org/z/c1nHkc
come back when you learn to program.

>call a function five times when one time wouldve sufficed
>"lol who cares"
nigger please

Absolute state of [go dilate]
>What an asbolute bloated and garbage language C is.
What? It's minimalist.
>Having to malloc() and free() just for to declare string is sheer autism.
HAHAHAHAHA you can't fucking be serious.

He's from San Francisco. The new street shitting capital of the world

Attached: 3f2.jpg (3000x3000, 368K)

Attached: wfwfee.jpg (250x250, 19K)

Imagine still using var in js lmao

Cheerp++ can do that.

AAAARRGH I'M COOOOOOOOOMIING

coding if for every one!

Attached: RBmExhkmpF-6.png (300x250, 43K)

Attached: java 2.jpg (500x600, 60K)

based

assert(obj != NULL);

have fun crashing your programs just because you ran out of memory.

>programming in FORTH
allot-dragon dragon-rise dragon-whatever

>Make and enforce your own rules about how data structures should be created and defined
>Basically assembler but better
>use about half or less of C's memory usage.

>>why? inst it freed when the main function ends?
>not using superior gcc
__attribute__((cleanup(free))) obj *

also wtf is ur reaction image you fucking nonce

>just
lad...

>braces not on new lines
triggered

C is horribly inefficient compared to JS.

Attached: 1504750786191.jpg (638x479, 101K)

explain?

How would OP's JS example crash?

ASSERT(3) Linux Programmer's Manual ASSERT(3)

NAME
assert - abort the program if assertion is false

SYNOPSIS
#include

void assert(scalar expression);

crash, abort, unexpected exit, whatever. Out of memory doesn't always need to be a fatal error

>doesn't know what the stack and heap are

based
cringe

I know what asserts are. You haven't answered my question.

Don't cast the return of malloc. The C language is guaranteed to properly cast it implicitly. Adding the cast only adds to effort required to read and understand the code.

What's your favorite way to handle oom in helloworlds?

>get null pointer from malloc
>program aborts when asserting it isn't null
isn't it obvious

delete something else I don't need. Use static alloc instead of malloc/dynamic allocation.

Is this from this JavaScript/TypeScript to C transpiler github.com/andrei-markeev/ts2c

this isn't embedded
wtf are we supposed to do, add a nano sleep and keep trying until the kernel gives us a pointer?

There's usually not enough unneeded stuff in helloworlds to make the first approach applicable. I probably could somehow get rid of boring junk like .got and .interp in the middle of the runtime (who needs it anyway, amiright?), but the memory hog that devoured the memory will just eat it too. This approach merely postpones the problem.

see
>delete something else I don't need.

Yes

Have you even read my question? Javascript doesn't require manual memory management.

>Javascript doesn't require manual memory management.
>compiling javashit to C
>C uses manual allocation
>C code can just abort randomly
>bbut, javascript doesn't use manual allocation!
stfu zoomer

You're fucking retarded.

>reddit spacing
ok zoomy, sure thing.

It's good that we both agree that you're retarded.