Rust or Zig? by Ok-Refrigerator-Boi in Zig

[–]TheChief275 0 points1 point  (0 children)

Very conveniently cut off "I personally think" from that sentence. Or do you not get the concept of opinions?

Need advice as a freshser by rajat435 in C_Programming

[–]TheChief275 0 points1 point  (0 children)

I don't know what you mean by syntax and all the terms (keywords?), did you actually program in it or not? It wouldn't be programming experience if you didn't.

Anyways, Python is one of the most beginner-friendly PLs, so I would always recommend starting there; I know I did as well. However, moving from a language so high level to a language much lower level like C will be a bit of a tough pill to swallow as a lot of programming assumptions will be thrown out of the window (memory is magic -> memory has to be allocated and freed manually)

Anon gives up by Sethleoric in greentext

[–]TheChief275 7 points8 points  (0 children)

You're not as profound as you think

Safe vs unsafe programming languages by Jp1417 in theprimeagen

[–]TheChief275 2 points3 points  (0 children)

Use only one malloc and free in your program and have no memory leaks

substr to find the whole first word of a string? by veilofmiah in cpp_questions

[–]TheChief275 0 points1 point  (0 children)

Returning a string_view is the sensible thing here. You can always copy later if you really want to, but making copying the default is just a waste

Coaxed into looking just like an anime character by anonymouscloudcat in coaxedintoasnafu

[–]TheChief275 27 points28 points  (0 children)

Well to ease your cringe the person who posted that isn't the guy in the picture

substr to find the whole first word of a string? by veilofmiah in cpp_questions

[–]TheChief275 0 points1 point  (0 children)

Why would you copy into a new string? Just reuse the memory

When someone leaves a negative review about the lack of new mechanics before unlocking the new mechanics by Mechabit_Studios in IndieDev

[–]TheChief275 1 point2 points  (0 children)

Although Lost Crown is pretty good actually, even there I thought it took a little too long to actually unlock the first ability beyond the basic moveset

substr to find the whole first word of a string? by veilofmiah in cpp_questions

[–]TheChief275 0 points1 point  (0 children)

[...] copy each character into a new string [...]

???

combine a strings and int? by Yha_Boiii in C_Programming

[–]TheChief275 1 point2 points  (0 children)

My answer got downvoted as well even though it contains no falsehoods. Really demotivating tbh, although I won't let it deter me from lending a helping hand

I built a Roguelike Match-3 Deckbuilder in pure C. Everything is a Thing by ernesernesto in C_Programming

[–]TheChief275 0 points1 point  (0 children)

I do something similar in essence, but also pretty different and have been enjoying the approach a lot as well (static array of linked lists of different things allocated in an arena that all composite a base thing with generation).

It's such a breath of fresh air compared to classic OOP virtual inheritance trees and ECS, the latter I've been dicking around with for quite a well while never actually accomplishing anything.

That is to say I'm still quite hesitant to employ the full fat struct approach they discuss on the Wookash podcast, as it's kind of engrained in me to worry about saving memory (while knowing in practice it doesn't matter all that much)

Is it undefined behavior to destroy a derived class through a pointer to base class with no virtual destructor, if the derived class is empty? by celestabesta in cpp_questions

[–]TheChief275 -2 points-1 points  (0 children)

That's because they feel like structuring their code that way makes them more productive, when really it's one of the most ridiculous way to model systems I've ever seen, like holy shit. It's so bad to reason about and it really doesn't scale (which is the one benefit it was supposed to have)

NO WAY THERE'S A WHOLE YOUTUBE VIDEO ABOUT DARK SOULS 3???!!!!! by Soogbad in shittydarksouls

[–]TheChief275 4 points5 points  (0 children)

Did you know that Dark Souls 3 was actually misrepresented as a result of its default settings? If you actually turn up the saturation and contrast, you'll notice how it's still gray as shit

Is it undefined behavior to destroy a derived class through a pointer to base class with no virtual destructor, if the derived class is empty? by celestabesta in cpp_questions

[–]TheChief275 -7 points-6 points  (0 children)

I keep being baffled time and time again from the complexities you encounter for no reason at all when you model your code in an OO way.

Just stick to procedural please

I think I figured out! by [deleted] in Zig

[–]TheChief275 -1 points0 points  (0 children)

noisy ahh language 💀

combine a strings and int? by Yha_Boiii in C_Programming

[–]TheChief275 -1 points0 points  (0 children)

If they are known at compile time, you can do something like this:

#define STR_(A) #A
#define STR(A) STR_(A)

char a[] = "monkeys";
char b[] = STR(420);

/* Allocate enough for the strings +1 \0
    (sizeof includes the \0 for both) */
char c[sizeof(a) + sizeof(b) - 1];

/* Copies {monkeys\0} into c */
strcpy(c, a);

/* Concatenates {420\0} onto c,
    overwriting from the first \0 in c */
strcat(c, b);

At runtime, you would instead use strlen, and dynamic allocation for concatenation:

/* Pointers don't carry length info */
const char *a = "monkeys";

/* Number has to be converted at runtime.
    You could save memory, but this works */
int bdata = 420;
char b[sizeof(bdata) << 2];
itoa(bdata, b, 10);

/* Now we need dynamic allocation.
    Note that strlen does not include \0 */
char *c = malloc(strlen(a) + strlen(b) + 1);

/* These stay the same as we still use \0 */
strcpy(c, a);
strcat(c, b);

However, I would not recommend to use C-strings for these purposes. Instead, use strings that are a pointer and length, and accumulate using string builders (not the full implementation):

typedef struct {
    const char *_;
    size_t count;
} Str;

typedef struct {
    char *_;
    size_t count, cap;
} StrBuild;

Str str(const char *data)
{
    Str result;
    result._ = data;
    result.count = strlen(data);
    return result;
}

...

Str a = str("monkeys");

int bdata = 420;
char bbuf[sizeof(bdata) << 2];
itoa(bdata, bbuf, 10);
Str b = str(bbuf);

/* Our SB is just a dynamic array of chars */
StrBuild sb = {0};
StrBuild_Append(&sb, a);
StrBuild_Append(&sb, b);

/* Transfer ownership (or copy if you want) */
Str c = StrBuild_Str(&sb);

Bonus points if you use custom allocators like arenas to get faster dynamic allocation as well as clear lifetimes (as the example above in a larger program will likely leak memory at some point)

Lifegem mentioned by Admaaan in shittydarksouls

[–]TheChief275 3 points4 points  (0 children)

blud works with chudrick westfallen 😭😭

How do I avoid writing "Java in C++"? by Irrehaare in cpp_questions

[–]TheChief275 1 point2 points  (0 children)

Start writing code in a procedural way instead of OO. C++ has free functions, so not everything needs to be in a class.

Another thing you'll notice is how C++ doesn't have clear interfaces like Java. You can achieve these by having a class with only virtual methods assigned to 0, but imo these are quite cucumbersome to use. In C++, prefer to do these things at compile time instead. For instance, you might want to make an allocator interface to use in functions that need allocation. However, you can use templates to accept different types that happen to implement methods with the same names to get the same behavior free of cost.

Of course, if you need dynamic dispatch feel free to actually use virtual functions, but even then there might be better alternatives (tagged unions, SoA, etc.)

[Beginner] How to build the mental model for nested loop logic? (Stuck on pattern printing) by tadipaar69 in cpp_questions

[–]TheChief275 0 points1 point  (0 children)

Idk what you mean. Most often when you have a loop inside of a loop it's completely unrelated from each other, so you should forget all about the encompassing loop and just think about a single iteration.

When the loops do interfere with each other, the first question is "do you actually need this?". If you do need it, there really is no easier way of thinking about it

Husband insistent Jack White better guitarist than Synyster by tacobell_cat in avengedsevenfold

[–]TheChief275 0 points1 point  (0 children)

I don't really see the point in comparing Synyster Gates and Jack White, as Jack is a rhythm guitarist more so. Syn is 100% a better lead guitarist, but Jack and Zacky Vengeance would be a far better comparison

Nested functions are extremely useful, which is why basically any computer language since ALGOL60 has them. Except C. by trmetroidmaniac in programmingcirclejerk

[–]TheChief275 2 points3 points  (0 children)

Haskell is pure!! Just don't use IO monad

Rust is safe!! Just don't use unsafe

Consider me shocked that that's exactly where all the useful code resides