17

To clarify, I mean writing scripts that generate or modify classes for you instead of manually writing them every time, for example if you want to replace reflection with a ton of verbose repetitive code for performance reasons I guess?

My only experience with this is just plain old manual txt generation with something like python, and maintaining legacy t4/tt VS files but those are kind of a nightmare.

What's a good modern way of accomplishing this, have there been any improvements in this area?

[-] Cyno@programming.dev 17 points 3 months ago

If our content gets federated to threads then it just means that google results will point to it first rather than to us, they will probably have better indexing and search features than the fediverse. People will also probably think the content originated on threads too (since that's where they see it and threads could easily obfuscate info like that) instead of who actually made it.

It could increase the short term engagement but in the long run, it will just serve to make threads better.

9

I don't have access to my router and my ISP charges for port forwarding (I think they might have a CGNAT setup?).

I'm trying to work around that since I want to start hosting some apps and game servers from my PC. I'm seeing a lot of talk about tailscale as a possible solution to this but honestly I'm a bit confused with all the options and whether this is actually the proper tool for the job.

Assuming it is, do I go the route of setting up a "tailscale funnel" or a "subnet"? Will other people have to install tailscale too if they want to join my servers? People also mention Netmaker or Cloudflared Tunnel, although it also seems like cloudflare doesn't want their tunnels used for game and media traffic?

The more expensive option I guess would be just paying for protonvp premium since it offers port forwarding in that case, but I'm not sure about performance and whether it's worth it, at that point I might just rent a server instead.

Hoping you folks at self-hosted have more ideas on how can I, well... self host instead of throwing money at the problem.

[-] Cyno@programming.dev 3 points 7 months ago

Was pretty simple in Python with a regex to get the game number, and then the count of color. for part 2 instead of returning true/false whether the game is valid, you just max the count per color. No traps like in the first one, that I've seen, so it was surprisingly easy

def process_game(line: str):
    game_id = int(re.findall(r'game (\d+)*', line)[0])

    colon_idx = line.index(":")
    draws = line[colon_idx+1:].split(";")
    # print(draws)
    
    if is_game_valid(draws):
        # print("Game %d is possible"%game_id)
        return game_id
    return 0

            
def is_game_valid(draws: list):
    for draw in draws:
        red = get_nr_of_in_draw(draw, 'red')
        if red > MAX_RED:
            return False
        
        green = get_nr_of_in_draw(draw, 'green')
        if green > MAX_GREEN:
            return False
        
        blue = get_nr_of_in_draw(draw, 'blue')
        if blue > MAX_BLUE:
            return False    
    return True
        
            
def get_nr_of_in_draw(draw: str, color: str):
    if color in draw:
        nr = re.findall(r'(\d+) '+color, draw)
        return int(nr[0])
    return 0


# f = open("input.txt", "r")
f = open("input_real.txt", "r")
lines = f.readlines()
sum = 0
for line in lines:
    sum += process_game(line.strip().lower())
print("Answer: %d"%sum)
[-] Cyno@programming.dev 4 points 7 months ago

Oh god, sorry to hear that ๐Ÿ˜…i'm feeling desperate enough to try that, i just wrote a different implementation and i get the same (wrong) result. At this point I just want to know what i misunderstood or mistyped cuz its driving me crazy

[-] Cyno@programming.dev 2 points 7 months ago

I'm stuck on one of these intricacies now! I saw some of the ideas on how other people did it but i honestly have no clue what i did wrong. Got any tricky examples to share?

[-] Cyno@programming.dev 2 points 7 months ago

If you find or run into that article later please share it, I'd definitely like to read it!

[-] Cyno@programming.dev 2 points 7 months ago

I'm not caching or reusing method results however, and even the inputs are not necessarily cached for multiple uses. I'm just preparing all potentially required input data before the method is actually called so I don't have to do any loads within the method itself, so the method is just pure code logic and no db interaction.

For example, imagine you have a method that scores the performance of an athlete. The common "pattern" in this legacy code base is to just go through the logic and make a database load whenever you need something, so maybe at the beginning you load the athlete, then you load his tournament records, then few dozen lines later you load his medical records, then his amateur league matches, etc.

What I do is I just load all of this into a cache before the actual method call, and then send it into the method as a data source. The method will only use the cache and do all the calculations in-memory, and when it's done the result would be in the cache as well. Then outside of the method I can just trigger a save or abandon it to persist the result. If I want to unit test it, I can easily just manually fill a cache with my data and use it as the data source (usually you'd have to mock custom response from the repository or something like that, inject an in-memory repository with the same data anyway or just resign to using an integrated test).

It's like I'm "containerizing" the method in a way? It's a pretty simple concept but I'm having trouble googling for it since I don't know how to call it.

11

cross-posted from: https://programming.dev/post/6513133

Short explanation of the title: imagine you have a legacy mudball codebase in which most service methods are usually querying the database (through EF), modifying some data and then saving it in at the end of the method.

This code is hard to debug, impossible to write unit tests for and generally performs badly because developers often make unoptimized or redundant db hits in these methods.

What I've started doing is to often make all the data loads before the method call, put it in a generic cache class (it's mostly dictionaries internally), and then use that as a parameter or a member variable for the method - everything in the method then gets or saves the data to that cache, its not allowed to do db hits on its own anymore.

I can now also unit test this code as long as I manually fill the cache with test data beforehand. I just need to make sure that i actually preload everything in advance (which is not always possible) so I have it ready when I need it in the method.

Is this good practice? Is there a name for it, whether it's a pattern or an anti-pattern? I'm tempted to say that this is just a janky repository pattern but it seems different since it's more about how you time and cache data loads for that method individually, rather than overall implementation of data access across the app.

In either case, I'd like to learn either how to improve it, or how to replace it.

1
submitted 7 months ago* (last edited 7 months ago) by Cyno@programming.dev to c/csharp@programming.dev

Short explanation of the title: imagine you have a legacy mudball codebase in which most service methods are usually querying the database (through EF), modifying some data and then saving it in at the end of the method.

This code is hard to debug, impossible to write unit tests for and generally performs badly because developers often make unoptimized or redundant db hits in these methods.

What I've started doing is to often make all the data loads before the method call, put it in a generic cache class (it's mostly dictionaries internally), and then use that as a parameter or a member variable for the method - everything in the method then gets or saves the data to that cache, its not allowed to do db hits on its own anymore.

I can now also unit test this code as long as I manually fill the cache with test data beforehand. I just need to make sure that i actually preload everything in advance (which is not always possible) so I have it ready when I need it in the method.

Is this good practice? Is there a name for it, whether it's a pattern or an anti-pattern? I'm tempted to say that this is just a janky repository pattern but it seems different since it's more about how you time and cache data loads for that method individually, rather than overall implementation of data access across the app.

In either case, I'd like to learn either how to improve it, or how to replace it.

[-] Cyno@programming.dev 2 points 7 months ago

I only have half as much experience as you, and none with Go specifically, so I can't give you any good answers but I can say I empathize - the company I work at is also stuck with a legacy monolith that's still on .net framework and everything is so coupled that it's impossible to even unit test, less alone deploy the projects separately. Some people aren't bothered even with the basic principles of code writing and the senior people are just overworked and can't keep tabs on it even if they wanted to.

The worst part is that the company is mostly either juniors just doing what they are told or older seniors that are stuck in their ways and are afraid of anything new - although as I got older I started to see why that might be the correct approach, not everyone wants to learn and adapt to new tech and it's a big ask of the upper management to risk it on that. Basically we're just repeating the same mistakes and wasting time fixing known errors that keep happening and any actual improvement or proper removal of tech debt never happens.

So yeah... I'm starting to believe that "clean good code" only happens either in hobby projects or new startups. Any larger, "stable" codebase of a larger company is going to be an inefficient mess however ๐Ÿคทโ€โ™‚๏ธ

[-] Cyno@programming.dev 8 points 7 months ago

I agree completely. The discussion was what we replace English with however.

I'm not in favor of replacing English, I'm just saying if we want an alterantive I don't want it to be a nation-specific language again, so to speak.

[-] Cyno@programming.dev 3 points 7 months ago

It's a neutral, easily accessible language. Having it in programming could incentivize more people to learn it as well.

[-] Cyno@programming.dev 6 points 7 months ago

I'm not disagreeing outright but... Why do we need more non English programming languages? Is there a specific practical reason?

The only language translation I'd maybe consider to accept in programming is Esperanto. Anything else just sounds like a terrible idea.

17

Was just wondering what's popular nowadays, maybe I find something new and better - what kind of tools are you using to access and manage databases?

I'm personally using Dbeaver a lot but honestly it feels increasingly more buggy and unreliable as time passes, every installation and update has had (unique) issues so far and there's little support. However the ease of use and some powerful, convenient, utilities in it make it preferable to others.

[-] Cyno@programming.dev 3 points 7 months ago

I use the CLI for simple commands, especially if helping someone on another PC and I don't have access to my preferred tool, but I honestly don't get people who use it religiously and never even try tools with GUIs. The convenience of being able to easily see the commit history, scroll through it, have a right click context menu or ability to just click it and see file changes (and then right click those files for additional options), is just something I can't abandon. Nowadays even the aliasing can be replicated in those tools if they support creation of custom commands so even that is a moot point - with some setup you can be as fast as with a CLI.

2

It is a common sentiment that managing dependencies is always a big issue in software development and the reason why so many apps come pre-bundled with all the requirements so it reliably works on every machine.

However, I don't actually understand why is that an issue and why people generally bash npm and the way it's done there. Isn't it the simplest and most practical solution to a problem - you have a file which defines which other libraries you need, which version, and then with one command you can install them and run the program?

Furthermore, those libraries and their specific versions can be stored elsewhere and shared across all apps on a system so you can easily reuse them instead of having to redownload for each program individually.

I must be missing something since if it were that easy, people would have solved it years ago and agreed on a standardized best way, so I'm wondering what is the actual issue and a cause of so many headaches.

9

I see this often with both new and old developers, they have one way of doing a thing and when presented with a new problem they will fall back to what they are used to even if it's not the optimal solution. It will probably work if you bruteforce it into your usual patterns but sometimes, a different approach is much easier to implement and maintain as long as you are willing to learn it, and more importantly - know it exists in the first place.

On a less abstract level, I guess my question is - how would I go around learning about different design patterns and approaches to problem solving if I don't know about their existence in the first place? Is it just a matter of proactive learning and I should know all of them in advance, as well as their uses?

Let's for example say I need to create a system for inserting a large amount of data from files into the db, or you need to create some service with many scheduled tasks, or an user authentication system. Before you sit down and start developing those the way you usually do, what kind of steps could you take to learn a potentially better way of doing it?

view more: next โ€บ

Cyno

joined 8 months ago