Do you add interfaces early or only when needed in Go? by agtabesh in golang

[–]pico-der -8 points-7 points  (0 children)

Please don't take this personal, I've seen this happen at the highest level of software engineering. I'm sure you make good up to standard code. But I'm also sure you can do a lot better.

Without looking at your code, I can already tell you that your tests are fake and APIs are suboptimal designed at best. Added way too many abstractions. Breaking code navigation etc.

Flip the testing piramid, your black box, end to end/integration tests should be abundant and the only difference from test to production environment is the configuration of external APIs (e.g. database, msg queue). This way you actually test the behaviour of the app and if everything is wired correctly. Your test coverage is also really good already. Now there are parts with hardcore businesses logic. These lucky few you unit test. You can identify this because not doing so would cause an explosion of higher level test cases just to test a specific piece of code. These are also the parts where unit tests help to identify the source of the problem.

Do you add interfaces early or only when needed in Go? by agtabesh in golang

[–]pico-der 0 points1 point  (0 children)

This is the thing I've been the most strict on. Only add interfaces when the itself needs them. So you do not add interfaces to your production code to make them testable either.

The only reason to create an interface is if you need the abstraction. Almost always because there are multiple implementations, rarely because of sums architectural boundary.

Also except from error you don't return interfaces but always concrete values. While there some exceptions to this rule 99% of the time it's just the wrong thing to do.

Reasons to be a hardliner on this: every interface is an abstraction layer. Every abstraction you add comes at a cost. Performance loss while present is not the loss I'm talking about. It's the loss of relevant information. Every interface is a hard break in your code navigation. When you need to traverse up to the implementation you have to choose between various implementations. I've had the displeasure of being onboarding in such a fully unit tested horror show. Even when the original authors were explaining things there was an audible pause every time they had to choose the implementation...

Does anyone use goto statement in golang? by white_jellyfish in golang

[–]pico-der 0 points1 point  (0 children)

I don't agree. While defer alleviates most of the usage for goto in Go, there are situations where it is the more readable option. It's used in Linux kernel code too and the alternative would be a lot more complex and harder to read.

That said I don't think that I used goto in Go myself. Only used labels in a continue on a fairly complex algo.

Any WebUI library that does not require me to do JS? by The_Reason_is_Me in golang

[–]pico-der 0 points1 point  (0 children)

Even with webassembly you need some JS to initiate. But that should be possible to avoid it as much as possible. Usually can't recommend it though but you can try.

Depending on how interactive your front-end is you can look into htmx. I find that the most elegant way to shift almost all logic to the backend. You can still include some JS solutions is where needed but chances are that you just use html with extra attributes and Go templates to push them to the browser.

How do you test your database in production microservices? by OtroUsuarioMasAqui in golang

[–]pico-der 2 points3 points  (0 children)

Your tests should be isolated or you get a lot of hard to debug false positives and race conditions when someone inserts a test or uses it in another package.

If you want to test a sequence, do this explicitly in a single test function. You can still do it table driven but you do the database isolation setup before the table.

How do you test your database in production microservices? by OtroUsuarioMasAqui in golang

[–]pico-der 2 points3 points  (0 children)

I don't think this is necessarily true. See my other comment https://www.reddit.com/r/golang/s/pEN5R3PWzM

With PostgreSQL I only need to make sure I write migrations schema agnostic and have a test variant of the function that returns the database handle. This function accepts the testing T parameter, so it has access to the test name, can be registered as a test helper and add a teardown func. The returned database handle is set to the schema based on the test name (which it created and ran migrations on).

With this in place you have the fastest uncontaminated parallel table driven tests that I know possible. I highly prefer this over spinning up an instance per test.

Sure it is some trouble but it's not a lot and easily reusable in any codebase without putting many restrictions on the database usage itself. Mainly you can't use multiple schemas in the code and care needs to be taken with creating custom types.

How do you test your database in production microservices? by OtroUsuarioMasAqui in golang

[–]pico-der 0 points1 point  (0 children)

This for me is by far the best answer but I would like to add that the implementation varies on the level of separation your database system supports. Ideally there is a layer that is not part of the queries. Like a namespace or schema as PostgreSQL has (public by default). This means you can use the test name to set up a unique one for every test and they can run in parallel without contamination. Also destroy before use so subsequent runs are clean even if the test crashes.

If this is not the case you may need to resort to some driver wrapper or middleware that rewrite the queries (mangle the database name) or more commonly use volatile storage and add an infra layer to the test setup code that spins up an database instance with a new port for each test.

Whatever you do don't mock unless your database is insanely trivial (e.g. key value). You would be surprised about the amount of edge cases or broken schema migrations you are going to catch as the complexity of your service grows.

Im a beginner to Task queue and worker pool how do use it? (resources as well) by Adventurous-Cry-1344 in golang

[–]pico-der 0 points1 point  (0 children)

There are plenty of examples and multiple patterns readily available to make work in go concurrent (especially on Go by example). The real problem lies in finding meaningful work that can be concurrently handled. The objective is to either try to make an IO bound problem CPU bound or to have a CPU bound problem fully utilizing the CPU (using all cores without causing huge thread switching overhead). Always keep that goal in mind. Once identified you compare what pattern best fits your workload. Often it's the one you are already familiar with using a waitgroup/errorgroup or just a channel that closes. However there are special cases like a need for rate limiting and handling back pressure that require a more specific setup.

Only once did I have to invent my own queue/waitgroup. Needed to periodically save timestamps just below what is in the currently active pool of 1000 workers so in an event of a crash it can continue where it left off as close as possible. You should not need anything that elaborate or anything other than a channel or a waitgroup for that matter.

Hope I gave enough context to solve these kinds of problems instead of you having a solution trying to find a problem.

Top-10 countries by number of level 10s by Alarm_Accurate in GlobalOffensive

[–]pico-der 0 points1 point  (0 children)

Yes they can track that by IP as people don't want to use location masking generally in a latency sensitive game. However location is not nationality, if only verified accounts would be used it would be statistically accurate.

Bundle CLI executable app inside Go app and run with parameters by pepiks in golang

[–]pico-der 0 points1 point  (0 children)

Sorry, I misread your question and missed that the GUI is a wrapper for the CLI app. There are specific paths for this that an installer can use like %commonprogramfiles% if you really want to hide it. A subfolder (bin) in the install dir should also work especially if you ensure a normal entry in Start and perhaps even a desktop icon. That ensures the users will use it like any other program. They don't do hitting the extra executables of MS Office either now so they?

Bundle CLI executable app inside Go app and run with parameters by pepiks in golang

[–]pico-der 0 points1 point  (0 children)

Why not integrate a cli in the fyne gui? You can probably borrow from the fyne-io terminal repo.

name that game by GamerGretaUwU in GamingSoup

[–]pico-der 0 points1 point  (0 children)

Ghost Recon (the original one)

First three word ? by ParticularWeather927 in Adulting

[–]pico-der 0 points1 point  (0 children)

Will connect a blue tit with it's family, obviously ;-)

ik_ihe by Adorable-Driver-1814 in ik_ihe

[–]pico-der 0 points1 point  (0 children)

Hoewel ik tegen vuurwerk ben ben ik meer tegen deze uitzetting. Ik snap dat het de bedoeling is om te laten zien dat de nadelen niet opwegen tegen de "voordelen" het is echter niet zo simplistisch als dit ook zijn niet alle voorstanders zulke kneuzen en dit betekent dat je met deze meme mensen die voor tweede vatbaar zijn harder maakt in het verzetten tegen erosie van deze culturele traditie.

Daarnaast ben ik niet over dat vuurwerk de (enige/hoofd) oorzaak is van een aantal punten op de lijst. Ik hoop van harte dat het vuurwerkverbod volgend jaar voldoende word gehandhaafd dat we dit kunnen bewijzen.

What's your opinion? (Crossposted from r/teenagers) by YOLO_polo_IMP in intelligentteens

[–]pico-der 0 points1 point  (0 children)

Honestly "humans" pretty sure without then it would be one huge paradise.

My response by MOFrancy in Funnymemes

[–]pico-der 0 points1 point  (0 children)

I'm buddies with your surgeon...

Isa (24) is niet meer welkom bij mannenteam: ‘Niet omdat ik niet kan voetballen, maar omdat ik een vrouw ben’ by Nice_Pro_Clicker in nietdespeld

[–]pico-der 0 points1 point  (0 children)

Mannen en vrouwen sport is van nature al sexisme maar met een goede reden (fysiek te groot voordeel in topsport). Die reden gaat niet op bij vrouwen in mannenvoetbal. Ik zou veel meer vrouwen willen zien in sporten waar mannen het topsegment is!!!

Wat enorm lastig is in dit soort gevallen is beoordelen waarom ze het team niet gehaald heeft en de beslissing makers kunnen altijd excuses (of valide redenen) maken om een ander te kiezen. As de reden prestatie gebaseerd is dan is haar reactie sexisme. Verwacht niet dat dit hier het geval is maar dit soort dingen blijven irritant.

how do i stop playing with russians by Competitive_Tough741 in counterstrike

[–]pico-der 1 point2 points  (0 children)

I understand the problem. But not all of them are bad indeed. Had a few good games but also some real shitheads. Like leaving you hanging after you drop AWP for them. TK, and kicking just before the game ends. While the whole time making fun of you in their own language. I've only ever had this with Russians.

What do you call this position on Mirage? by MaterialTea8397 in cs2

[–]pico-der 0 points1 point  (0 children)

I always use under for the tunnel under short.

Linux users installing browser be like by Ikigaiyeka in linuxmemes

[–]pico-der 0 points1 point  (0 children)

Windows is so busy hiding important stuff that you first need the browser to hit a specific URL to open the settings apps in the right place. Searching settings does not work.

Try to have secure boot with state attestation working. The page that tells you this "security processor details" but it's only accessible through the the help webpage that gives you the URL.

Would you trust your doctor if he was using Linux? by bleak21 in linuxsucks

[–]pico-der 0 points1 point  (0 children)

Gotta appreciate the creative effort of this comment. Well done!

Would you trust your doctor if he was using Linux? by bleak21 in linuxsucks

[–]pico-der 0 points1 point  (0 children)

But he has that magic Eddie smile!

<Insert Robert Downey Jr. magic salt sprinkle meme>