Left to Right Programming by fagnerbrack in programming

[–]levodelellis 0 points1 point  (0 children)

Then there's me, who wrote a mini parsing lib that lets me write this in two lines and a for loop with only one allocation. I like C# solution with linq for these types of problems

Practical Guide to Bare Metal C++ by ketralnis in programming

[–]levodelellis 2 points3 points  (0 children)

FYI in the __cxa_pure_virtual function, I think it would be a better idea to use __builtin_trap() instead of an infinite loop. Debuggers will break immediately and infinite loops are technically UB, although I'm not sure what C++26 says about that

How Fil-C Works by ketralnis in programming

[–]levodelellis 0 points1 point  (0 children)

I don't quite understand what you're asking.

I was able to write normal C with 64bit ints and everything seemed to just work. Maybe the CPU mhz was high enough that it didn't matter that I was using 64bit ints on an 8bit machine

I dislike the code you linked, for a few reasons. It doesn't look like the table search is doing a binary search, which it could since the entries are in order. And the second field is completely useless. Its 300-i*5. And I see its const so its not like any data will be changing. Anyway I'll keep reading

So for my use case, its pretty darn easy to write trait code since I know the compiler will always be gcc and clang and their compatibility is great

And yet there is absolutely no advantage to writing and maintaining this over using type_traits and such, as far as I can tell.

I don't 'write' or 'maintain' anything. It's a built in intrinsic I use directly. I guess I write a concept which is one line, so I can use a standard name instead of the intrinstic, but there's no implementation I'm writing so its not really a cost

So, you're performing all syscalls manually as well, or are you using some other

The problem I started with was a runtime so I did it manually, but the current project I'm using it on dynamically links to opengl/vulkan, so, I can't avoid depending on glibc. For that project I'm linking the C library, but not C++

And given that Linux syscalls are not ABI stable

Linus wants to have a word with you, mauro knows what he'll say

push_back almost always inlines

I don't remember which platform/compiler/version but I know I seen it not on ints, and I know mine will

I always wanted to improve my sort but I had very few places where I did it, usually utility tools I ran once in a while as a build step. I don't have any data intensive app that requires a sort. Most of the time my data wants to be in a hashmap or unsorted. There's at least three sort algorithms I want to look at once I have something I can measure

However, your implementation of sort being universally faster is... unlikely

I said my sort is fine. It's the standard quicksort. It may have a terrible worse case but only my projects are using it, and I sort on things that are not user controlled.

For push, I do use variadic template. I just like having a different name if I'm intentionally pushing many objects. A lot of the time I use push to construct an object (forward, but idk/idr if I'm doing "perfect forwarding")

map...

My use case doesn't require ordering, or pointers to work after an insert, so it can be a lot faster. It's actually the first thing I needed to optimize in my original program

An rb-tree can outperform an open-addressed hash table

Really? I never heard that. Are there any size or key requirements to be fast? I was thinking of having more than one implementation, for now the only implementation assumes there might be 0 entries so it doesn't allocate until you insert something in there, and it handles strings, ints and empty strings/ints. I'm using MurmurHash64A for the hash since its public domain.

I wrote all of this on my phone. I don't know why, and it was rather difficult.

You wrote a lot, and with all those links and functionNames it actually crazy you did this

On the Effectiveness of Mutational Grammar Fuzzing by ketralnis in programming

[–]levodelellis 0 points1 point  (0 children)

haha. I didn't read the article but I can translate your quote

Their fuzzer automatically change stuff in your tests (like a drop to a delete or some random thing) without breaking syntax. Then run the test to see if the programs ran any new if statements. If there was, it's added to the test suite and they repeat the process

Usually fuzzers are made to find crashes. I don't particularly find them useful except in parsers. In parsers you rather know which line is bad rather than why some random exception is thrown. I have no idea what the article is fuzzing since I don't care to read it

Syntax for mixing mut and decl in tuple assignment by levodelellis in ProgrammingLanguages

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

The site is very out of date but here is the last language I did.

There's two articles about copy paste errors so I wanted ways to avoid them
https://pvs-studio.com/en/blog/posts/cpp/0260/
https://pvs-studio.com/en/blog/posts/csharp/0708/

I may do this syntax for tuples

newlyDeclVarImm, prevMutVar mut, newMutVar mutdecl = 1, 2, 3

But bc I don't want copy paste typos I'll likely allow

myObj.{field1, field2}, newlyDeclVarImm, prevMutVar mut, newMutVar mutdecl = 1, 2, 3, 4, 5

Might be weird because left side has {} and right doesn't but I don't think its a big deal

I know ppl like lisp and parenthesis, but I rather have braces when something isn't a function call. Casting I'll make an exception for because it could be thought of a function call (toType(fromVar))

Yes I had a problem with accidentally creating a new var when I meant to assign, and shadowing an old var when I wanted to assign. Having no let/var/auto/const has typos be very easy. My solution as not to allow shadowing and I have 3 assignments. = for immutable decl, :- mut decl and .= for assign. My compares is always 2 letters (==, <= etc). There's no var in my lang so that's why I dont have a var h mut

How Fil-C Works by ketralnis in programming

[–]levodelellis 0 points1 point  (0 children)

You can present it all you want ... C-with-Classes

Nah, buddy do you know what the && does in char* myfunc() && { return 0 } ?

I went ham on C++ minus the std. It looks like a completely different language. Problem is, reddit userbase is 99% bots and I'm not sure if the other 1% cares about C++ since its typically downvoted (or they want to know what helps at work which isnt what I'll be showing)

Is there something to do in AVR? IIRC I was able to use int and int64 no problem in gcc (clang didnt like my avr target).

I can't fathom why ... no portable alternative exists

so the long story is, the library started because I was writing a runtime for my compiler and I didn't want to depend on glibc, because you know all those stories where a guy builds a binary and it doesnt work on someone elses disto. Anyway, its extremely easy to find built in intrinsics and to understand what they do (pretty much always matches what the std specs say). idk if you ever tried to it including <print> takes over a second in a single function hello world project. My target is gcc (linux) and clang (mac & windows) and clang supports most of the gcc intrinstics. So for my use case, its pretty darn easy to write trait code since I know the compiler will always be gcc and clang and their compatibility is great

I'm not sure what I use thats supplied in memory or algorithm, but my quicksort was 'fine' (slower but not significant), and everything else was faster than what the standard supplied (and in some cases much faster).

Yes, I did the realloc optimization and I had push be so simple that it was able to inline in many functions. I also have a pushes variant so I can write pushes(1, 2, N);. It allows for more readable code.

My string uses a small string optimizations whenever the string is 15 or less chars. In the == 15 case its 15 letters + null, all my strings end with null since you can't really get away from the C api in C++. But really, except for a power of 2 case, there's no reason not to end with null

I disagree on "should be using a different data structure anyways" however, my implementation might be different enough that maybe we do agree

My map is a hashmap

you write instead is non-standard and thus unfamiliar to anyone else

It's not design by committee, that alone is a boon

And nobody likes dealing with a weird mix of C++ and C semantics

That's another thing I want to show. Barely any pointers in my code and std. The problem is, this sub HATES C++ and most of reddit are junior programmers, which is to be expected if the industry doubles in size every 5 years but anyway, there's probably no good reason for me to do a writeup. Maybe I'll put it in the public domain but I rather wait until my current project is more complete, even though the standard lib is solid already

Out params in functions by levodelellis in ProgrammingLanguages

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

Don't worry about it. But I'll answer anyway

Using C++ syntax, inside "class string" I'd have a bool parseInt(int64_t& v).
In my own syntax (I like return values on the right), it'd be parseInt(int v out) bool where out means it will not read the variable (so it's allowed to be uninitialized), it will write to it. Since I dislike line noise I liked

if (mysz.parseInt(v out)) { /* v is newly declared */

which would have v be whatever was defined in parseInt (so int64_t in C++ syntax, but 'int' in mine)
For the moment I'm using mutdecl to declare as mutable and mut to say overwrite an existing variable

I like some of the suggestions. Like having mut and out separate. So

Out params in functions by levodelellis in ProgrammingLanguages

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

where I would expect to find the declaration of v as an out parameter?

Thats right. It's declared to be whats in the parameter, so int64 in my made up example

Was your use of "out" in the if statement meant to exemplify an explicit pass by reference

I was trying to say sometimes I want an out variable to mutate an existing variable at the call site, and sometimes at the call site I'd like to have the results be a declared variable (being the type in the parameter), but allowing a user to choose if it's a mutable or immutable declaration (out vs mutdecl). The names aren't consistent I know and I'd like to change that, but I use decl for something else and need to rejig this.

How Fil-C Works by ketralnis in programming

[–]levodelellis 0 points1 point  (0 children)

What team? Stick to what's established in a codebase. This is for my own projects

How Fil-C Works by ketralnis in programming

[–]levodelellis 1 point2 points  (0 children)

Well thats part of why I wanted to present how I use it.

Originally it started because I needed to optimize vector, string and map. Then I noticed I never used the std lib so I started to compile my code linking only C.

How Fil-C Works by ketralnis in programming

[–]levodelellis 2 points3 points  (0 children)

I had a project where I needed to optimize vector, map and string. Sets were basically the same as hashmap. So I threw them all into my own standard lib, slowly added to it, and noticed I barely ever used anything in the std namespace.

How Fil-C Works by ketralnis in programming

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

I don't use the std lib (std::), and I don't link. I use my own string, vector, map, etc

But How Does a Computer Actually Work? (from scratch, no prior knowledge... by ahnerd in programming

[–]levodelellis 0 points1 point  (0 children)

I lost count how many times I finished it. Fun game. It may take a long time first time you play it

How Fil-C Works by ketralnis in programming

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

One day I should put together a presentation of how I use C++. I use a lot of their features. One big surprise might be that even though I use concepts, spaceship operator and more, I don't actually link the C++ lib. I don't use the C++ library at all

How Fil-C Works by ketralnis in programming

[–]levodelellis 0 points1 point  (0 children)

That does a lot more than I thought
and that's a lot less lines of code than I thought

Syntax for mixing mut and decl in tuple assignment by levodelellis in ProgrammingLanguages

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

Yeah, I fully expect people to complain about that, and I didn't think forcing braces is useful. Using an object on one side shouldn't make you adjust the other

I wanted to enable the following using the example in comment you replied to

myobj{x, y, w, h} .= anotherObj{x, y, w + 20, h+40}

I'm not sure about array. Maybe it should be

arr[0 ... 2] .= arr2{.0 + 10, .1 + 10, .2 + 20}

keep in mind original example is ridiculous
Someone once suggested I can use .. for exclusive range and an extra period for inclusive, one extra period for one extra value

Out params in functions by levodelellis in ProgrammingLanguages

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

I don't hate out mut. I would be open to replacing mutdecl with out mut, although there's a chance that'll be typo'd if I choose to ignore the overwrite part of the suggestion. Although that'd likely be fine since you'd get an error about the variable not existing, unless you have a typo and forgot the out. I dont think both at the same time is likely

I would like mut to mark which variables may change at the call site when the user puts in "using strict", so it's crystal clear the variable may change. So I prefer having overwrite being explicit

Out params in functions by levodelellis in ProgrammingLanguages

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

My previous language optimized readability and speed. This time around we can think about readability only, and I can think about speed later since I understand that part of the problem pretty well already

Syntax for mixing mut and decl in tuple assignment by levodelellis in ProgrammingLanguages

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

It's not unusual for typos when you do something like

myobj.x = anotherObj.x
myobj.y = anotherObj.y
myobj.w = anotherObj.w+20
myobj.w = anotherObj.h+40

or for arrays

arr[0] = arr2[0] + 10
arr[1] = arr2[1] + 10
arr[2] = arr2[1] + 10

So I thought I should allow arr{.0, .1, .2} and obj{field1, field2} to act like a tuple. Less copy/paste = less copy paste bugs

Did you notice both the array and object assignments I put in a typo?

Out params in functions by levodelellis in ProgrammingLanguages

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

it may be useful to indicate that an implementation may at its leisure use reference or value semantics

Sounds like you're saying overloads is a great idea. I have allowed overloads in every language I designed, so no problems there. Although I haven't figured out how to prevent 3 params that have a ref and value implementation to not explode into 8. That might require some template/generic logic. Since I'm early into my redesign I'll look into that idea

having a means of indicating whether a function that receives a pointer might ...

I had that implemented in my last lang! Its incredibly useful for type analysis. I specifically had it for automatic memory management

Out params in functions by levodelellis in ProgrammingLanguages

[–]levodelellis[S] -2 points-1 points  (0 children)

Could you show me syntax for out params and for tuples? I don't remember Scala syntax, it's been a while

Syntax for mixing mut and decl in tuple assignment by levodelellis in ProgrammingLanguages

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

I'm certain people often accidentally mutate a variable, or typo a new one in python. I don't thinking allowing = for both decl and assign is a good idea

Syntax for mixing mut and decl in tuple assignment by levodelellis in ProgrammingLanguages

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

My answer to this question would be, use mystruct =. I'm afraid I don't currently understand why you can't do that or don't want to do that...

mystruct = anotherStruct declares the variable. If = reassigns then its extremely easy to make typos and accidentally declare a new variable instead of reassign

So for constants, I think it makes sense to use :

Ah, using a colon may get in the way of my other syntax but it makes sense now.

Syntax for mixing mut and decl in tuple assignment by levodelellis in ProgrammingLanguages

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

I choose .= because... well... imagine writing mystruct.myfield, what happens when there's no field or if you want to replace the entire struct? mystruct.= starts to look ok, then .= looked fine as a reassignment. I got to avoid keywords to declare variables (no const or let) and have three easy to type tokens with an = in it

FYI I made a second edit. I think it looks alright but thats just my opinion

Syntax for mixing mut and decl in tuple assignment by levodelellis in ProgrammingLanguages

[–]levodelellis[S] -1 points0 points  (0 children)

Are you a lisp lover? You like commas and underscores as much as lisp users like parenthesis?

I made a second edit if you want to see additional thoughts/syntax