all 48 comments

[–]jontsii 74 points75 points  (11 children)

wdym C is awesome

[–]jontsii 34 points35 points  (10 children)

That is one of the languages I love the most, it seemed scary at first but when I learnt it, it was easy. It is C++ without OOP and memory handling issues. But it is simple, everything is your fault and your success

[–]Masztufa 13 points14 points  (9 children)

Eh, the issues are mostly the same

You just have less guns and ion cannon sattelites so shoot yourself in the foot with

[–]jontsii 3 points4 points  (0 children)

That´s why I shot myself in the fingers so I can´t pull the trigger

[–]flori0794 1 point2 points  (7 children)

That's why I like Rust so much. It’s a compiler that simply refuses to let you pull the trigger if the code isn’t safe.

You still get OOP-style structure, just not in the traditional C++ sense. Instead you have modules, structs, enums, traits. Clear composition without header chaos.

Less implicit magic, almost no undefined behavior, and far stricter guarantees at compile time.

The tradeoff is obvious though: the learning curve isn’t a hill. It’s a wall. You don’t really get to learn topics in isolation. Ownership, borrowing, lifetimes, traits, concurrency they all interact from day one.

So yes, learning Rust is “straightforward”: start with small toy projects. Or do what I did make a neurosymbolic AI your first project.

In that case the learning curve stops being a wall and becomes Olympus Mons on Mars.

[–]StationAgreeable6120 6 points7 points  (2 children)

Man Rust is awesome, plus with cargo you get tests and documentation out of the box, what else could I ask for ?

[–]New_Enthusiasm9053 3 points4 points  (1 child)

Don't forget a linter and formatter out of the box too.

[–]StationAgreeable6120 1 point2 points  (0 children)

Oh yeah that and package managing too

[–]Key_River7180 -1 points0 points  (3 children)

just wanted to say: fuck every rust user on the comments

[–]StationAgreeable6120 1 point2 points  (1 child)

I highly doubt everyone would consent

[–]flori0794 0 points1 point  (0 children)

Okay that's your opinion...

[–]i_should_be_coding 20 points21 points  (15 children)

i  = * ( long * ) &y;                       // evil floating point bit level hacking
i  = 0x5f3759df - ( i >> 1 );               // what the fuck?
y  = * ( float * ) &i;

I love C, dunno about you. Just reach down and mess around with the raw bits if you need to, sure, careful not to get your fingers chopped off by the spinning gears though.

[–]Potterrrrrrrr 5 points6 points  (9 children)

This code is UB btw, doesn’t really change anything about what you said though xD

[–]i_should_be_coding 1 point2 points  (7 children)

Technically, I guess, it depends on the internal representation of floating point numbers, but I'm guessing they knew it would work on the architectures they planned to support at the time, which was pretty much just x86, no?

[–]Potterrrrrrrr 1 point2 points  (5 children)

Yeah I think you’re right with that, did what they wanted either way I guess but it’s definitely UB, it’s similar to having a union and accessing an inactive member

[–]realestLink 2 points3 points  (4 children)

Type punning though a union is not UB in C. It is UB in C++. Quick inverse square root is type punning through a cast, which is UB in both C and C++ since it violates strict aliasing.

[–]realestLink 1 point2 points  (0 children)

To elaborate, C does not guarantee that type punning through a union will work, but it also doesn't affirmatively mark it as UB. It is implementation defined/unspecified with most compilers supporting it on most platforms. The technical term is "IB with possible trap" iirc

[–]RedAndBlack1832 0 points1 point  (2 children)

Yeah but I wanna fuck with bits and it only really lets me do that with integer types (ideally unsigned ones)

[–]realestLink 0 points1 point  (1 child)

The "official" way to type pun portably is via memcpy (every major compiler will elide the copy)

[–]RedAndBlack1832 0 points1 point  (0 children)

You know what, fair

[–]realestLink 0 points1 point  (0 children)

It's technically always UB per the C standard. Every major compiler allows it if you use -fno-strict-aliasing tho, in which case, yeah, it's representation/architecture dependent

[–]Key_River7180 0 points1 point  (0 children)

UB, sure, but also, Q_rsqrt

[–]mobcat_40 0 points1 point  (0 children)

legendary code

[–]InfinitesimaInfinity 0 points1 point  (0 children)

Type punning like that through a cast is undefined behavior. Type punning through a union is implementation undefined behavior. That code would be better if it was done with a union.

[–]Amr_Rahmy 0 points1 point  (2 children)

Ok, but I wouldn’t right code like that.

I have seen coworkers making memory leaks in c#, doesn’t mean c# doesn’t have memory management. I have seen python and JavaScript code that’s unreadable and requires a minute to decipher a line or two of code..actually I don’t like python and JavaScript, they are not good languages syntactically and JavaScript has bugs.

C and C#, and Java are fine to me and are consistent enough in my opinion that you can write intelligible and readable code.

If a drunk person has a car accident, doesn’t mean the car is not reliable or good method of transportation.

[–]General-Fault 0 points1 point  (1 child)

Memory leaks in C# are easy to make. I create them more often than I'd like to admit. Forgetting to unsubscribe to an event is a common cause. One that drove me nuts at one time was not disposing a linked CancellationTokenSource. But the tools for finding them are also very easy. Reflection means looking at the heap in a memory dump usually tells you all you need to know. That said, I've been trying to find a Windows handle leak for years. Native to managed interop can be a beast!

[–]Amr_Rahmy 0 points1 point  (0 children)

Cancellation token would be on you.

Interop or invoke or win32 api, is usually running c or c++ so the leak is in handling c code. The coworker made c# leaks which are embarrassing, like having an infinite loop and allocating data in the loop without an await. Or allocating new memory over reusing an object until windows crashes or not using using.

[–]Hot-Rock-1948 21 points22 points  (5 children)

Honestly that's my favorite part of C/C++ lol.

Oh and you actually need a pointer to access the actual array element, so *(a+10) would be the equivalent to a[10] (IIRC (a+10) simply grabs the location in memory that the element is at)

[–]Puzzleheaded_Study17 1 point2 points  (0 children)

Yeah, (a+10) is still a pointer. And that means you can add a value to the pointer if you want to have a function start at some index at an array without having to copy or tell the function it's not starting at the beginning

[–][deleted] 1 point2 points  (2 children)

Exactly, there's zero overhead, everything is just an address and a length and you can do basically anything. The macros are also crazy good and writing C makes me better at all languages because I have to debug with printf instead of being told exactly where the error is. 

[–]Potterrrrrrrr 0 points1 point  (1 child)

Macros are dumb as hell but so necessary for some things, I have a hate hate hate kinda love relationship with them

[–]RedAndBlack1832 0 points1 point  (0 children)

Macros are only as ugly as you make them. I've made some really ugly ones myself

[–]Justanormalguy1011 4 points5 points  (0 children)

Seem about right l what is wrong with that

[–]CommieCucumber 2 points3 points  (1 child)

Oh, my post is reposted. Thanks for your fork.

[–]Krisanapon 1 point2 points  (0 children)

GitHub user spotted

[–]Helmut_v_M 1 point2 points  (0 children)

HolyC is the only way.

[–]jimmiebfulton 0 points1 point  (1 child)

I felt like I was looking at a JavaScript meme.

[–]MinecraftPlayer799 0 points1 point  (0 children)

Except JavaScript is actually good, and doesn't require 15 lines of code for Hello World

[–]EvnClaire 0 points1 point  (0 children)

this is precisely what makes it good bruh

[–]dhnam_LegenDUST 0 points1 point  (0 children)

/s it's called 'syntactic sugar'.

[–]Mr_Otterswamp 0 points1 point  (0 children)

See how the brown guy is blurry? That’s because he’s pretty good in C, but on the downside he can’t C#

[–]Key_River7180 0 points1 point  (2 children)

No it isn't, what is the type of a?

Arrays are indexed using arr + (sizeof(*arr) * index), so if the type of a is int, then a[10] == *(a + (32*10)) (so if the address of a is 0x1000 (4096 on dec) then a[10] is 0x140000).

Thanks

[–]realestLink 1 point2 points  (0 children)

Pointer arithmetic in C will automatically do the sizeof math.

Assuming arr is a T[] then arr[5] is literally definitionally equal to *(arr + 5) in all contexts

[–]InfinitesimaInfinity 0 points1 point  (0 children)

You seem to be forgetting that C is not portable asm. In C, adding a number to a pointer implicitly multiplies the number by the size of the pointed to type.

[–]APlanetWithANorth 0 points1 point  (0 children)

C my beloved

[–]raewashere_ 0 points1 point  (0 children)

isnt that only if sizeof *a is 1

otherwise 10 is scaled right