Small Programming Tricks
Posted by signa11 1 hour ago
Comments
Comment by kccqzy 58 minutes ago
Comment by louthy 29 minutes ago
Is this just plain old rage baiting? I literally can’t tell any more.
Comment by kccqzy 5 minutes ago
Comment by teekert 52 minutes ago
Comment by bigstrat2003 7 minutes ago
Those are also the current days if you have any sense. It's a bad idea to run an LLM with access to your machine at all, but if you absolutely must, you better review everything it does to make sure it doesn't run anything insane.
Comment by kccqzy 4 minutes ago
Comment by gnoack 19 minutes ago
The "Unix Power Tools" book is an excellent source for Unix and shell usage tricks
Comment by cachvico 1 hour ago
Comment by CableNinja 59 minutes ago
Comment by FlyingSnake 55 minutes ago
Comment by samdixon 31 minutes ago
Comment by bufordtwain 1 minute ago
Comment by overflowy 1 hour ago
Comment by disinterred 26 minutes ago
Comment by NegativeLatency 1 hour ago
I would find that annoying, however to not be seen as a jerk I wouldn't say anything.
Comment by CableNinja 1 hour ago
I frequently do the same, but not everyday; only when i think its something actually useful/helpful beyond the everyday crap. Most recently, we have had a huge push to use ai (just like everywhere else), ive been getting pretty creative with it, and at this point have a well polished setup that i can give a shitty sentence on a problem, not only does it understand the task, but theres a full ticket->branch->work->pr review->ready comment flow that it uses. My team also uses ai but they havent quite wrapped their head on ways to really work with it. I have built and shared a number of helpful things with the team to try and help them grow. One such thing was a doc i had my ai instance write, based on how ive been using my setup. This alone has started to get the rest of the team up to where i am.
My team doesnt share the same types of things i do, but they still share helpful things.
Call it what you will; I think if youre not helping your team grow by providing insights and helpful things, then youre not the kind of person i want to work with.
Comment by NegativeLatency 54 minutes ago
One is actually helping and the other is making yourself more visible to mgmt for promotions.
Comment by metabagel 28 minutes ago
Comment by davidee 12 minutes ago
Share knowledge? I don't think anyone here is arguing against that in any way (or conversely arguing for hoarding knowledge).
The concern, one I share, is where the sharing has to happen publicly "every day" - so no matter how trivial, useless, niche, overly-specific the tip is (whatever, the list isn't exclusive), someone shares it.
That's the part that's not sharing knowledge for the benefit of others, but rather self-serving. I might even go so far as to say self-serving doesn't even need to be selfish; the person might genuinely believe they're doing good, but even there, self-serving.
TLDR: Share your knowledge, don't make sharing something every day, even when you don't have something valuable to share, your target.
PS - if this note irks anyone (are routine maxxers a thing?), make the goal to learn something every day, then share where appropriate.
Comment by blooalien 1 hour ago
Comment by saulpw 1 hour ago
Annoyance is a clue; not about them, but about you.
Comment by NegativeLatency 53 minutes ago
What I'm saying is I am not a jerk and actually do care about my coworkers, however I also don't want a bunch of noise in a chat app I have to use to do my job.
Comment by owebmaster 36 seconds ago
Comment by simlevesque 7 minutes ago
Comment by NegativeLatency 2 minutes ago
>I shared a trick on slack every day with the engineering team
Comment by winternewt 1 hour ago
Here's one that I think more people should know: avoid branches. If I can do the same thing without an if statement and even a logical expression, the code typically both becomes easier to understand for people and easier to run for the CPU.
Comment by happytoexplain 44 minutes ago
I have always felt like my bar for publishing something (even just to internal wikis/channels) is too high due to being overly self-conscious. I think we should try not to validate that feeling by implying that there is a non-negligible number of readers who will think you have a personality flaw because you wrote down your personal collection of tips in a public place, or that those people deserve consideration in the first place.
There is no such thing as "the things everybody knows". There are just too many things. Even a list of basic tips is probably going to contain one thing I didn't know or perhaps forgot. Write-ups like this are where most of my practical knowledge comes from, not RTFM (which I do).
Comment by cachvico 1 hour ago
Comment by cestith 48 minutes ago
It's not applicable to every situation, but one way to do this is some very basic fuzzy logic. You do a little math and then either choose a single branch at the end, or sometimes avoid a branch altogether. https://www.geeksforgeeks.org/artificial-intelligence/fuzzy-...
Another way to avoid some branches is to have specialized routines, maybe with multiple dispatch, rather than more general methods with a bunch of checks within them for slightly different situations.
A classic performance hack for critical sections is loop unrolling.
Comment by NegativeLatency 17 minutes ago
Like imagine you have a few different classes of things A,B,C so instead of checking if the thing you're handling is an A,B,C you have like a shared interface across all and can call Thing.do_it or whatever.
Still branching conditionally but it's passing it off to language features instead of code you have to write.
Comment by craftkiller 53 minutes ago
Comment by metabagel 16 minutes ago
=====
Should you go branchless?
Most of the time, no. Branchless code is harder to read and easier to get wrong. Besides, compilers know a lot of tricks and already do a lot of this work for us.
Only when a profiler points at a hot loop, and the loop contains a branch on unpredictable data this technique can pay off big.
Comment by metabagel 48 minutes ago
Comment by robby_w_g 33 minutes ago
Comment by jamiejquinn 36 minutes ago
Comment by cestith 47 minutes ago
Comment by corps_and_code 51 minutes ago
if (thingThatIsTrue):
// a bunch of logic here...
else: // different logic here...
they mean:if (thingThatIsTrue):
return doThisWhenTrue()
return dothisWhenFalse()Just a simple example. I'm not sure if this is what you consider "obfuscating" the branches. Logically the same, but a bit more linear to understand?
Edit: I am bad at formatting comments here.
Comment by owebmaster 3 minutes ago
Comment by bryanrasmussen 48 minutes ago
if Val === "A" then Do funcA() else if Val === "B" then
and so forth for lots of values, or using a switch statement or similar branching instead of
Object functions = { "A": funcA() {does what funcA does}, "B": funcB() {does what funcB does} etc. etc.
}
runnableFunction = functions[val]; runnableFunction();
Actually writing it I remember now someone who did this, a junior who had to update a validation function for XML invoices based on their root namespaces, which there could be a large number of these, and so she wrote out
switch namespace == "somenamespace" { validatingscheme = "someschema"; doPreliminaryFunctionToDetermineifshouldvalidate(); }
I can't remember all the details as this was almost 20 years ago, however while it was true that one branched on the schema, it made much more sense to look up what one was supposed to do based on the rule for branching and then just execute that one action rather than writing a bunch of branching logic.
So to make it more concrete: Once branching rules becomes sufficiently complex prefer query for what you should do rather than branching
on edit: note again, not real code, but should be understandable and translatable into real code to understand what is being said easily enough.
on 2nd edit: this is also just basically one of the things I prefer instead of getting a lot of branching logic. I have never seen any stats on any benefit to this model than just having a bunch of branching statements, but I feel that the benefit is there nonetheless.
Comment by cestith 1 hour ago
Comment by metabagel 51 minutes ago
Comment by lscharen 47 minutes ago
total = calculateOrderTotal(user.order);
if (user.isPremiumMember) {
total = total * 0.9; // 10% discount
versus total = calculateOrderTotal(user.order);
discount = calculateDiscount(user); // Returns 0.9 or 1.0
total = total * discount;Comment by reaperducer 1 hour ago
Or stupid, like all those vloggers posting "ZOMG! Go all in with these secret hidden weird trick iPhone life hacks to level up!" that are just regurgitating what's in the manual.
As we used to say, RTFM: https://support.apple.com/en-us/docs/iphone
Comment by jawns 1 hour ago
Comment by kccqzy 1 hour ago
Comment by farrellm23 1 hour ago
Comment by popzxc 1 hour ago
IMHO the value of these nuggets is that you understand what you're doing and why; opening yourself to large amounts of non-default behavior likely will end up in a less than pleasant setup.
Not taking into account that different users might disagree on what is convenient and what is not, which is basically the point of making things configurable.
Comment by AJRF 1 hour ago
Comment by jonstaab 50 minutes ago
Comment by wiredfool 1 hour ago
Comment by aDyslecticCrow 1 hour ago
Record a debugging terminal session including output to a file. Its pretty great.
Comment by VCFundedGenYer 1 hour ago
Comment by IsTom 59 minutes ago
Comment by ahmedhossamdev 1 hour ago
Comment by okinternets 59 minutes ago
Comment by elendilm 1 hour ago
For me, I personally use nothing fancy other than normal KDE Kate for backend development.
Function and variable names are chosen after putting a lot of thought into it which also includes being amenable to grep and sed.
Comment by williamcotton 1 hour ago
In the macOS terminal you can...
Ctrl + Option + -
...and it'll undo your typing.Dunno about other OS keys!
Comment by behnamoh 1 hour ago
I remember learning a lot of these programming tricks over the years. They would give me happiness: learning something new about nvim, or some new shortcut in the Fish shell, or a new Vim macro, or the difference between 1 bracket or 2 brackets in Bash scripts, etc. But now it seems like all of them are irrelevant, and I wanted to see how others think about the situation.
Comment by SoftTalker 1 hour ago
I'm fortunate I guess in that most of my work tasks have very loosely defined deadlines, if any at all.
Comment by louthy 24 minutes ago
I write everything myself. After 41 years of coding, I think in code — code flows from my brain through my fingers effortlessly: translating my thoughts to English for an LLM to then translate back to code is much, much slower than me.
JetBrains Rider has an AI auto-complete which I do use for the 5-10% of the time that it can predict what I’m going to write next.
Disclaimer: I’m not writing vanilla line-of-business code or bog standard web apps, so I suspect I’m just not in the training data.
Comment by bigstrat2003 1 minute ago
Comment by dgacmu 1 hour ago
Comment by huurtehoog 1 hour ago
Analysis and any artifacts are all handcrafted by me. I mean, that is the work. I have never seen papers or code as an outcome. What I want is to learn and enable other to learn. That I can only get from doing the work myself.
Comment by bradly 1 hour ago
Comment by catlifeonmars 1 hour ago
I don’t mean this to brag, mostly to point out that in my line of work, actually writing the code is not the biggest bottleneck.
For context I work on greenfield network security appliances
Comment by spprashant 56 minutes ago
Comment by skydhash 1 hour ago
Comment by acedTrex 1 hour ago
So i still get daily use out of these tricks.
Are there people that are literally ONLY interacting with a computer via an LLM? thats crazy if its true
Comment by adzm 1 hour ago
;with [[[]][[[](_)as(select 1 union select 0),[[]][]][](_)as(select 1 from [[[]][[[] []]]][]]],[[[]][[[] _),[]][]][[](_)as(select 1 from [[]][]][] []]]][]]],[[]][]][] _),[[[[[]][](_)as(select 1 from []][]][[] []]]][]]],[]][]][[] _),[[[]][]]](_)as(select 1 from [[[[[]][] []]]][]]],[[[[[]][] _)select _ from(select row_number()over (order by _)from [[[]][]]])[[[]][[[](_);
/s
Comment by rdevilla 1 hour ago
Comment by Natashash23 1 hour ago
Comment by monideas 1 hour ago