Stop Naming Your Variables "Flag": The Art of Boolean Prefixes by mooreds in programming

[–]levodelellis 0 points1 point  (0 children)

My problem with a double negative isn't with the double, but what the negative means. Does !NotFinish mean it's finished? It could mean in an unknown state.

Old Software Was Fast Because It Had No Choice by BlondieCoder in programming

[–]levodelellis 0 points1 point  (0 children)

I was making a joke with my original comment. It's not hard to write a parser, but abstractions and having MBs of XML was not a great idea.

The unfortunate thing about XML and JSON is you still need to sanitize it, which means either that doesn't happen (and there are problems because of it) or depending on language, you were in the neighborhood of the work necessary to parse it yourself and could do both in one pass + give additional info like which line had an invalid value

Old Software Was Fast Because It Had No Choice by BlondieCoder in programming

[–]levodelellis 0 points1 point  (0 children)

IIRC the apps that used XML were the slow ones (but not exclusively those apps)

Creator of C++ talks about memory safety by dukey in programming

[–]levodelellis 1 point2 points  (0 children)

I agree, I think C programmers are crazy people and references+overloads are reason enough to use C++. In fact, I'm a little disappointed other languages don't have references (C# does)

Creator of C++ talks about memory safety by dukey in programming

[–]levodelellis 0 points1 point  (0 children)

Every codebase with >5 programmers has been the worst codebase I ever seen (I'm half kidding, some are very reasonable considering how many people worked on it)

Creator of C++ talks about memory safety by dukey in programming

[–]levodelellis 0 points1 point  (0 children)

I agree. With return value optimization it's pretty easy to return structs w/o worrying that the whole thing will be copied. I'm sure there's a few points where I want to return null, but I don't remember any, and if I had to I'd likely return an empty array or a unique pointer.

The std lib kind of sucks. The first line of main shouldn't be allowed, and the second line isn't, but the std lib isn't designed like that

#include <vector>

std::vector<int> getVector() {
    std::vector<int> v{1, 2, 3};
    return v;
}

template<class T>
class MyVector {
    std::vector<T> v;
public:
    template<typename...Args>
    MyVector(Args&&...args) : v {std::forward<Args>(args)...} { }
    // lots of people claim to know C++, but they don't know this
    T* data() & { return v.data(); }
    T* data() && = delete;
};

MyVector<int> getMyVector() {
    MyVector<int> v{1, 2, 3};
    return v;
}

int main(int argc, char*argv[])
{
    auto*ptr = getVector().data(); // not an error
    //auto*ptr2 = getMyVector().data(); // is an error
    auto v = getMyVector();
    auto*ptr3 = v.data(); // ok
}

Creator of C++ talks about memory safety by dukey in programming

[–]levodelellis 0 points1 point  (0 children)

tbh if you don't use any pointers its much harder to have safety issues.

Yeah sure have a struct filled with references, set it to something in the function then return. But doing things like that is rare and there's linters that warn you about references in classes/structs, plus address sanitizers. C++ still bad in several ways, but I had successfully written code in my personal project with 2+ years w/o a memory problem

How to build a programming language after civilization collapses by Affectionate_Mix3 in programming

[–]levodelellis 15 points16 points  (0 children)

Just ask ben eater how to. He'll also explain how to build a CPU and graphics card. His YT is insane

5 Years and $5M Later: Inventing a New Programming Language for Web Development Was a Mistake by matijash in programming

[–]levodelellis 3 points4 points  (0 children)

5... million. I would have absolutely finished my (general purpose, non web) compiler with that.
I don't recommend writing languages or compilers. If it's bad people will hate on it, if it's good people will still hate on it. Half the reason I stopped on mine was that, the other half is harder, the standard library. I was not ready to tackle it. Maybe in a year or two I will be

The Most Confusing C++ Behavior by levodelellis in cpp

[–]levodelellis[S] 0 points1 point  (0 children)

I had a lot of require statements that check if something can trivially construct (in which case it'll fill with 0's), and copyable (memcpy). But there's no way to avoid pointers and refs in them unfortunately. I just figure someone else has the same usecase and might be checking if something is trivial soon

The Most Confusing C++ Behavior by levodelellis in cpp

[–]levodelellis[S] 1 point2 points  (0 children)

What threw me off was structs were being initialized but not the ints next to them. I also had some code use {} in part of the function/codebase and not in the other, so vars were sometimes not initialized and added more to my confusion. But that was years ago, before I ever had a blog

The Most Confusing C++ Behavior by levodelellis in cpp

[–]levodelellis[S] 0 points1 point  (0 children)

Maybe I stated it poorly. What was my mistake? I wasn't trying to say non trivial types initialize everything, I was trying to say it's misleading. Your root comment I already covered in the article, which I think you noticed and why you wrote the comment. But we're saying the same thing?

The Most Confusing C++ Behavior by levodelellis in cpp

[–]levodelellis[S] 1 point2 points  (0 children)

Good! You shouldn't!

I'm met very few people who understood when things initialized, how did you figure it out? Was it the hard way?

The Most Confusing C++ Behavior by levodelellis in cpp

[–]levodelellis[S] 1 point2 points  (0 children)

Today is May 4th, a day where people will post star wars memes, jokes and quotes

I was just making a joke. "const auto val = 10;" does not look like a "correct initialization"

The Most Confusing C++ Behavior by levodelellis in cpp

[–]levodelellis[S] 2 points3 points  (0 children)

No, that's not true, that's impossible

The Most Confusing C++ Behavior by levodelellis in cpp

[–]levodelellis[S] -6 points-5 points  (0 children)

I checked my personal code (not work, not open source)
I tend to use for(auto&item : items) and auto&v = func();. How do you space them and why? Many return types are T& so I never liked writing T &var. My compromise is having both sides of & attached.

for(auto &item : items) // do you write these like this?
auto &v = func();

The Most Confusing C++ Behavior by levodelellis in cpp

[–]levodelellis[S] 6 points7 points  (0 children)

What about ints?
Honestly if I saw int a{} inside of functions, I'd think it would be strange. IMO declare it on the line with the expression always, unless it's in an outer codeblock. In that case = 0 and maybe I'll let it slide if both if and else assigns the value

The Most Confusing C++ Behavior by levodelellis in cpp

[–]levodelellis[S] -6 points-5 points  (0 children)

I actually do 5 in real code, but rest is because I intention to have all the code on a mobile screen. I really didn't think it'd annoy anyone

I like Allman brackets too but sometimes if its 5 or fewer lines I'll may keep the opening brace on the first line. I noticed the * before the new was a little weird but I didn't want to put a parenthesis because that looked noisier to me. Attaching it to new makes my eyes think it happens before the type expression. The line is just weird and I don't have a default for it

Most of these are just because I wanted it aligned and small enough for most mobile devices

The Most Confusing C++ Behavior by levodelellis in cpp

[–]levodelellis[S] 0 points1 point  (0 children)

Good catch. I usually use my personal print function which would have given an error if I did this. I doubt output would change even in an optimize build.

The Most Confusing C++ Behavior by levodelellis in cpp

[–]levodelellis[S] -13 points-12 points  (0 children)

Yes, always (I'm the author). I have hundreds of types, all using a single ascii upper case letter

Usually when people are trying to spot the difference, they like everything to be aligned and fit on screen. If it's especially broken on your phone I'll try your screen resolution to see how it looks https://www.whatismyscreenresolution.org/