I Don't Trust My Own Code (lackofimagination.org)
from Aijan@programming.dev to programming@programming.dev on 28 May 2024 09:43
https://programming.dev/post/14740831

#programming

threaded - newest

bungle_in_the_jungle@lemmy.world on 28 May 2024 10:38 next collapse

Something I find helpful is to PR review my own code before I create the actual PR. It’s surprising how giving it a once over in a different setting to the comfort zone of your code editor can save you a bit of unnecessary back and forth.

stuckgum@lemmy.ml on 28 May 2024 13:01 next collapse

I wouldn’t do that, too much tunnel vision and biases. I just skim through and make sure everything makes sense. Especially naming and comments.

SatouKazuma@ani.social on 28 May 2024 14:54 next collapse

I think it makes sense, but only after logging out for the day and coming back to it a bit either the next day, or after a weekend in the case of code completion late Thursday or early Friday.

Kissaki@programming.dev on 28 May 2024 15:16 next collapse

I wouldn’t do that, too much tunnel vision and biases.

Absolutely not. Self-reviews are very productive. I can confirm this from my own work and my colleagues, who also find it so.

You’re of course free to vary the degree and depth of self-review, but tunnel vision and bias is definitely not overbearing and diminishing in those situations for us.

Someone else will of course see more, what you may not see due to tunnel vision. But that’s besides the point.

stuckgum@lemmy.ml on 28 May 2024 16:56 collapse

Weird, never heard of anyone doing this. Aren’t your team self reviewing the code while writing it?

Rogue@feddit.uk on 28 May 2024 23:03 next collapse

When you finish the final sentence of an essay or a report do you just submit it straight away? You don’t read it through?

Kissaki@programming.dev on 29 May 2024 09:07 collapse

How do you self-review while writing? What do you mean by that?

I see it as different phases of development, mindset, and focus. You inherently can’t be in multiple at the same time.

  1. Problem space and solution exploration - an iterative and at times experimental process to find and weigh solutions
  2. Cleanup and self-review - document your findings, decision-making, exclusions, and weighing, verify your solution/changeset makes sense and is complete (to intended scope)
  3. Reviews

It makes no sense to be thorough during experimental and iterative exploration. That’d be wasted effort.

After finding a solution, and writing it out, a self-review will make you take a systematic, verifying review mindset.

icesentry@lemmy.ca on 29 May 2024 05:45 collapse

I just skim through and make sure everything makes sense. Especially naming and comments.

What do you think a self review is?

[deleted] on 29 May 15:12 collapse

.

some_guy@lemmy.sdf.org on 28 May 2024 14:31 next collapse

I like to take any text and copy / paste it into a different editor. Inevitably, this changes the layout because of different font settings or window size or whatever else. Reading it in a slightly altered layout helps me catch a lot of tiny errors that my eyes otherwise glide past.

SatouKazuma@ani.social on 28 May 2024 14:54 next collapse

All hail the PR draft

magic_lobster_party@kbin.run on 28 May 2024 16:38 next collapse

I do that all the time. Sometimes I even realize I missed an even more obvious solution to the problem or how to better communicate the intent of the code.

groucho@lemmy.sdf.org on 28 May 2024 16:45 next collapse

Yep. This is the way. Also, you’d be surprised how many devs don’t run through their own QA steps before asking other people to verify.

Fades@lemmy.world on 29 May 11:22 collapse

Yep, shit devs will rely on those reviewing the PR to do their work for them.

groucho@lemmy.sdf.org on 29 May 19:47 collapse

Steps to test: “Idk try some shit”

Fades@lemmy.world on 29 May 11:17 collapse

It’s so fucking goddamn sad how rare this is. Personally I review changes when I push commits and review all changes personally before publishing the PR and requesting reviews. I’m a senior dev so I guess it’s just something that comes with time (if you care about the code you produce)

I swear to fucking god every PR review I do for younger devs and contractors we have to use (guess what country they’re from), I swear they don’t even look at their own fucking code once they’ve written it, let alone perform any sort of critical analysis. thoughts about any missed use-cases/optimization/future application and evolution? Nah!! That’s what the PR is for right? 🤬

As you said even just a quick once over make a big difference and somehow it’s not even close to common.

Damn I need to quit

NotMyOldRedditName@lemmy.world on 29 May 15:53 collapse

This is my typical experience as well, too many people don’t do a code review of their own PR first.

When I was a junior, I had this coworker who did all my reviews. I was doing my absolute best and wanted to show that I was learning, so I would review all my work before submitting it and think, how would he review and respond to this code.

That just stuck with me and it’s my normal practice now.

I eventually learned that’s not as normal as I thought. I also tend to give better code reviews than others.

Edit: the other thing I do is check in with who will be reviewing my code well before I submit anything someone might think is weird and have a discussion about it before the reveiw. If it’s weird, there might be a better way unless were stuck due to technical debt or something, and doing that early vs at the end usually saves time.

Fades@lemmy.world on 31 May 01:04 collapse

I had the exact same path to that habit as well! Good mentors make good devs!!

souperk@reddthat.com on 28 May 2024 10:39 next collapse

Me neither buddy, me neither…

Falsehoods About Time: … Time always moves forwards.

I had to learn this the hard way… I was working at a platform that pulled measurements from sensors. The sensors did not declare the timezone for the timestamps of the measurement and the platform broke down twice after daylight saving. The first time there were duplicated records which caused conflicts and the second one we weren’t handling impossible timestamps.

agressivelyPassive@feddit.de on 28 May 2024 12:01 next collapse

I had a client whose clock was just a few milliseconds behind the server’s, but due to timezone crap one hour in the past. And the signature was valid for one hour.

If the network just happened to be too congested, the validation failed. The next request went through just fine. Took us forever to find out.

barsquid@lemmy.world on 28 May 2024 15:50 next collapse

I sure do hate time zones.

NotMyOldRedditName@lemmy.world on 29 May 15:47 collapse

So say we all

AeroLemming@lemm.ee on 29 May 18:34 collapse

I don’t really get why people use any time other than ms/seconds since the epoch for anything other than displaying that time to the end user. Having time just be a single number with no time zone shenanigans makes writing logic like that so much easier.

agressivelyPassive@feddit.de on 29 May 19:09 collapse

Epochs aren’t that simple either.

First of all, local time can be relevant, so you have to store timezone information somewhere anyway.

Epochs are also somewhat iffy in regards to leap years or seconds.

And finally: write me an SQL to retrieve all entries submitted in 2022 using just epochs.

Timezones are annoying as fuck, don’t get me wrong, but simply ignoring them isn’t a solution either.

AeroLemming@lemm.ee on 31 May 21:48 collapse

I don’t really remember SQL, does it prevent you from using a range of values? I can understand why leap seconds would be an issue.

perviouslyiner@lemmy.world on 28 May 2024 14:05 collapse
jjjalljs@ttrpg.network on 28 May 2024 13:37 next collapse

I was a full time test engineer / QA person for a while. My motto quickly became “nothing ever works”.

Pretty much any ticket behind a static copy change would have some problem or oversight. Sometimes even those would (did you account for very narrow view ports?)

Good developers would take this feedback gracefully. “Shit, you’re right, I need to account for mobile users.”

Bad developers would get defensive and upset. “We barely have any mobile users (me: did you check?). Alan already approved so I’m merging. I don’t want to waste time on this”

JustBrian7872@feddit.de on 28 May 2024 13:47 collapse

As a dev I’ve been on both sides to be honest. Especially when there is pressure to finish the next task. I think it needs good planning to create enough time for these things.

In the end bad devs will still shut you up about things they are not interested in fixing…

jjjalljs@ttrpg.network on 28 May 2024 14:04 collapse

I’ve done a lot of “then go get approval from the stakeholder to go ahead with this bug/problem”.

If product wants it out now now now they can sign off on it not working on mobile, so when their boss has a fit about it I can point to the conversation where Ryan said it was fine.

I’ve mostly worked at smaller companies though.

NotMyOldRedditName@lemmy.world on 29 May 15:45 collapse

I’ve caught problems in code review and had to do this even.

Often it’s reading it and realizing there’s a complicated edge case or they missed something entirely.

Sure we can make a different ticket for that to move this along, but we’re getting product to agree first.

abhibeckert@lemmy.world on 30 May 06:51 collapse

Sure we can make a different ticket for that to move this along, but we’re getting product to agree first.

Ooof, I’m glad I never worked there.

QA’s job should be to make sure the bugs are known/documented/prioritised. It should never be a roadblock that interrupts work while several departments argue over what to do with a ticket.

Seriously who cares if the current ticket is left open with a “still need to do XYZ” or it gets closed and a new one is open “need to do XYZ”. Both are perfectly valid, do whichever one you think is appropriate and don’t waste anyone’s time discussing it.

NotMyOldRedditName@lemmy.world on 30 May 16:17 collapse

No one cares if you leave a ticket open due to a bug or incomplete feature

Product sure as hell cares if you’re going to ship a bug or incomplete feature.

Never worked at company that wasn’t the case in over 15 years.

Product owns the work they ask us to do. We do their bidding.

And we certainly aren’t allowed to just change the scope of tickets at our own discretion without checking in

tunetardis@lemmy.ca on 28 May 2024 14:04 next collapse

Falsehoods About Time

Having a background in astronomy, I knew going into programming that time would be an absolute bitch.

Most recently, I thought I could code a script that could project when Easter would land every year to mark it on office timesheets. After spending an embarrassing amount of…er…time on it, I gave up and downloaded a table of pre-calculated dates. I suppose at some point, assuming the code survives that long, it will have a Y2K-style moment, but I didn’t trust my own algorithm over the table. I do think it is healthy, if not essential, to not trust your own code.

Falsehoods About Text

I’d like to add “Splitting at code-point boundary is safe” to your list. Man, was I ever naive!

SatouKazuma@ani.social on 28 May 2024 14:52 next collapse

Rocket programmer (and engineer) here. Can confirm that time programming is hell. Don’t even start on DST.

NotMyOldRedditName@lemmy.world on 29 May 16:04 collapse

I’m sure many smaller companies had their own internal Y2K moment as they scaled and became a big hit, and realized they used a wrong datatype like int instead of long or something and shit was gonna break by XYZ date if they did nothing heh.

tunetardis@lemmy.ca on 29 May 17:01 collapse

Imagine if you were the guy who made the call on IPv4 addresses…

NotMyOldRedditName@lemmy.world on 29 May 18:12 collapse

Give it long enough and somehow the person who decided on IPv6 will feel the same as every piece of matter we want to interact with can be networked.

tunetardis@lemmy.ca on 29 May 22:37 collapse

I guess the MAC address guy is up next. 48 bits may not go so far if every light bulb is going to want its own.

NotMyOldRedditName@lemmy.world on 29 May 22:53 collapse

Apple won’t like that doomsday event lol

Obi@sopuli.xyz on 29 May 2024 10:24 collapse

Hey I know this place! I filmed there it’s in northern Ireland, behind the camera there’s an Observatory kind of building (round thing).