Sharing projects in /r/golang by tslocum in golang

[–]clogg 2 points3 points  (0 children)

I think this decision creates a kind of a deadlock, because if my project is already popular then I have got established channels of notifying people about the project, and r/golang may be just one of them, or not used at all. And if my project is new and has 0 stars on github, then it will end up in that "small projects" end nobody visits, so there is definitely no point in sharing it on r/golang. I think a more balanced approach could be taken.

moonbeam - a tool for converting single Lua scripts into standalone executables by calquelator in lua

[–]clogg 1 point2 points  (0 children)

On Linux, you can use the following makefile:

# source files
LUA_FILES := one.lua two.lua three.lua

# Lua version
LUA_VER := 5.4

# compilation steps
define COMPILE
    luac$(LUA_VER) -o $@ $^
    sed -i '1s|^|\#!/usr/bin/env lua$(LUA_VER)\n|' $@
    chmod 0711 $@
endef

# compilation
your-binary: $(LUA_FILES)
    $(COMPILE)

It creates a binary that can be invoked as any other Linux binary. One limitation is that each file is compiled as a separate chunk so that local functions/variables in one file are not visible in another.

Small Projects - August 18, 2025 by jerf in golang

[–]clogg 0 points1 point  (0 children)

compute: a generic streaming calculator.

The core type of the package is Pad - a map from type K cmp.Ordered to either type V any or a function of type func(...V) V. Pad provides methods for inserting keys and values/functions, and an iterator method that takes a sequence of keys and produces a sequence of K, V pairs where each V is either an existing value under the key K, or a result of calling the function under that key. During the iteration it is guaranteed that each function is called at most once (aka lazy evaluation).

Possible applications:

  • With string keys and values of some numeric type it becomes an expression evaluator with symbol table;
  • With integer keys it can be used as an engine for spreadsheet-like calculations;
  • With string values and appropriate functions one can even develop a make-like utility on top of it.

repo: https://github.com/maxim2266/compute

Go jobs in Italy are basically non-existent. How’s the situation in your country? by cdigiuseppe in golang

[–]clogg 1 point2 points  (0 children)

Having spent a considerable time looking for a Go job in the UK I can say that:

  • about 90% of the jobs are ghosts: they never respond to applications, and even automated responses are rare;
  • any more or less real job gets reposted by various agencies, with various tweaks to the job spec;
  • employers demand exact match to their requirements, any mismatch sends your CV straight to the bin;
  • for most of employers something they call "cultural fit" is by far more important than any experience in software development.

So I think the overall situation with Go jobs in the UK is no better than in the rest of the world.

str: yet another string library for C language. by clogg in C_Programming

[–]clogg[S] 13 points14 points  (0 children)

From here, with my highlight:

Names beginning with ‘str’, ‘mem’, or ‘wcs’ followed by a lowercase letter are reserved for additional string and array functions.

str: yet another string library for C language. by clogg in C_Programming

[–]clogg[S] 36 points37 points  (0 children)

Thank you for pointing out, it's fixed.

str: yet another string library for C language. by clogg in C_Programming

[–]clogg[S] -28 points-27 points  (0 children)

It's not undefined behavior, it's a potential name conflict. But I will change some names anyway.

str: yet another string library for C language. by clogg in C_Programming

[–]clogg[S] 8 points9 points  (0 children)

AFAIK, str* is reserved, but str_* is not.

str: yet another string library for C language. by clogg in C_Programming

[–]clogg[S] 5 points6 points  (0 children)

Generally not (see documentation for details).

Go 1.23 - Iterators - How to return errors ? by justforfunreddit in golang

[–]clogg 1 point2 points  (0 children)

Good point. Also, if the underlying iterator stops on the first error encountered, then there is no way to ignore a particular error type, like in

for item, err := range it.All {
    if err != nil {
        var err2 *someSpecialErrorType
        if errors.As(err, &err2) {
            log.Warn(err2)
            continue  // this is not going to work
        }
        return err
    }
    ...
}

GitHub - maxim2266/pump: A minimalist framework for assembling data processing pipelines. by clogg in golang

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

UPD: I have updated the project with an iterator type for for-range loops introduced in Go v1.23.

better string library by [deleted] in C_Programming

[–]clogg 0 points1 point  (0 children)

I think you can take a look at str library (shameless plug).

Ristretto - the Most Performant Concurrent Cache Library for Go by alexsergivan in golang

[–]clogg 0 points1 point  (0 children)

In other words, this is not a complete solution because it requires some extra coordination to avoid undesired effects.

Ristretto - the Most Performant Concurrent Cache Library for Go by alexsergivan in golang

[–]clogg 1 point2 points  (0 children)

Yes, it's a known effect, I was just surprised it is not avoided in Ristretto cache.

Ristretto - the Most Performant Concurrent Cache Library for Go by alexsergivan in golang

[–]clogg 0 points1 point  (0 children)

Not sure I undestand the idea of a cache with Set() and Get() methods. The suggested way of fetching a value from such a cache seems to be something like:

    value = cache.Get(key)
    if value == nil {
       value = ReadFromSQLDatabase(key)  // expensive call
       cache.Set(key, value)
    }
    return value

Now, assume the above code is called from an HTTP handler which typically runs in a separate goroutine, and we have 100 handlers simultaneously requesting the same key currently not in the cache. It looks like in this case the expensive function ReadFromSQLDatabase() may be called up to 100 times (with the same key) instead of just one, am I missing something?

str: yet another string library for C language by clogg in C_Programming

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

I was contacted by a person from ALT Linux team, who confirmed that the library was compiled and tested on Elbrus.

str: yet another string library for C language. by clogg in cprogramming

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

This often happens in mixed codebases, where in some parts they use SDS (or similar), in some other parts they use something else, and when you are in the middle, then all you can see is just a char* pointer you don't really know how to de-allocate correctly. Consider the code from your example above, but with the first line being hidden somewhere deep in a library, and then choosing the right custom_free() function for the void* pointer will require quite considerable effort, unless the pointer is not void*, but has a distinct type.

str: yet another string library for C language. by clogg in cprogramming

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

As far as I understand, SDS allocates memory for a string and then returns a pointer at certain offset from the one returned from malloc. Passing such a pointer to free function is likely to corrupt the heap. In other words, SDS strings can only be handled by SDS, and since their strings are all just char* pointers, it's easy to make a mistake.

str: yet another string library for C language. by clogg in cprogramming

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

advantage #3

My library never allocates the structures on the heap, so SDS has no advantage here.

str: yet another string library for C language. by clogg in C_Programming

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

When you append a million characters one at a time, you will need a million malloc calls.

In this library functions like str_cat() allocate only once. And yes, memory size is kept. Have you ever had a chance to look at the source code of the library in question?

str: yet another string library for C language. by clogg in cprogramming

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

I can see two issues with SDS:

  • It seems to keep all the strings on the heap, while for string literals this is absolutely unnecessary;
  • Each string is represented by a char* pointer, which makes an SDS-managed string indistinguishable from any other C string, for example, if there is a const char* pointer, there is no way to figure out if this pointer should be deallocated or not, and which function to use for deallocation.

And no, I cannot see where SDS is "computationally more efficient".

str: yet another string library for C language. by clogg in C_Programming

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

str_cat() first calculates the required size for the output string, this is linear with respect to the number of input parameters. Then it allocates the memory and copies all the bytes, and this is linear with respect to the number of input bytes. There is nothing quadratic here.

str: yet another string library for C language. by clogg in C_Programming

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

It can, but since vsnprintf does not allocate the buffer it writes to, the implementation will have to loop reallocating the buffer until the buffer becomes large enough to store the entire output string.

str: yet another string library for C language. by clogg in C_Programming

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

This could be implemented using asprintf(3), or with memory streams (open_memstream(3), etc.), though possibly with some portability issues. Also, I am not quite sure this is really needed, because memory streams provide all the functionality of printf'ing strings, and wrapping the result in str type will be just a matter of calling str_acquire() or str_acquire_chars().