- 0 Posts
- 810 Comments
Read the article about property based testing. It is the middle ground between what you are describing and practicality.
I often pair with myself, which sounds silly but you can write failing tests by yourself, it just isn’t as fun.
In a world where this needs to be solved with TDD there are a few approaches.
If you were pair programming, your pair could always create a new failing test with the current implementation.
Realistically I would want tests for the interesting cases like zero, positive even, negative even, and the odds.
Another approach would be property based testing. One could create sequence generators that randomly generate even or odd numbers and tests the function with those known sequences. I don’t typically use this approach, but it would be a good fit here.
Really in pair programming, your pair would get sick of your crap if you were writing code like this, remind you of all the work you need to get done this week, and you’d end up using modulus and move on quickly.
TDD has cycles of red, green, refactor. This has neither been refactored nor tested. You can tell by the duplication and the fact that it can’t pass all test cases.
If this looks like TDD to you, I’m sorry that is your experience. Good results with TDD are not guaranteed, you still have to be a strong developer and think through the solution.
normalexit@lemmy.worldto Asklemmy@lemmy.ml•What does everyone here do when you can’t sleep and are wide awake besides being on phone? [serious]2·3 days agoI’ll get up and go to another room. Try to read or do something until I get sleepy and try again.
normalexit@lemmy.worldto Linux@lemmy.ml•Could someone help me setup local file sharing? [Fixed]3·5 days agoCan you share your smb.conf?
normalexit@lemmy.worldto News@lemmy.world•US agriculture secretary says Medicaid recipients can replace deported farm workers1·5 days agoThis feels like a flimsy solution to the problem that will fail. I guess that when Medicaid recipients don’t/won’t/can’t sign up, the government will take away their healthcare and use slave labor from prisons to catch up.
I think in six months they will be saying: "hey we tried this idea with Medicare recipients, but they just wanted to stay home and play video games. Now our crops are in danger of not being harvested.
What if… We round up some of these bad prisoners and make them work for almost free!? That will kill two stones."
normalexit@lemmy.worldto News@lemmy.world•Detained as an illegal immigrant – MAGA mom still has faith in Trump's mass deportation plan11·6 days agoI mean she kind of has to. Probably the only chance she has.
What about those eight hours at night? I mean people hardly even think about work while they are dreaming.
normalexit@lemmy.worldto Showerthoughts@lemmy.world•Moving away from physical currency has been very detrimental to the homeless industry4·8 days agoThe homeless people in my area accept venmo and square cash. They put their details on their signs, which is pretty smart.
normalexit@lemmy.worldto Programming@programming.dev•This Overly Long Variable Name Could Have Been a Comment | Jonathan's Blog5·10 days agoClear concise code that reads like documentation is the ideal. Good function and variable names, formatting, and encapsulation play into this. Tests should document and describe the system.
If it still isn’t clear what the code is doing, and I’m all out of ideas (or time) for refactoring, a well placed, accurate comment is fine. It needs to be kept up to date like any other artifact in the project.
It’s harder to keep comments accurate than code, since code can be executed and tested. I use them sparingly; when I’ve otherwise failed to write clean code, or the code is just so complex that it needs to be described.
Comments are just another tool in the toolbox. If they add clarity to the situation, by all means, use them.
If you can think of an expressive variable name that lets you skip a comment eg “employeeCount”, instead of “e” // number of employees, do that.
normalexit@lemmy.worldto No Stupid Questions@lemmy.world•How do you all keep the area around the toilet paper dust-free?2·10 days agoLittle bit of spray cleaner and a cotton rag.
normalexit@lemmy.worldto Asklemmy@lemmy.ml•What is the first thing you'll do if one day your identity gets purged from all records and no one recognizes you?5·12 days agoProbably try to get my identity back. I’m not trying to escape anything currently, and not having documentation is a dangerous thing in the world these days.
normalexit@lemmy.worldto News@lemmy.world•Trump calls on Federal Reserve chairman Jerome Powell to quit immediately3·12 days agoThey continue to find new and innovative ways to make the nightmare worse.
normalexit@lemmy.worldto News@lemmy.world•"Big, beautiful bill" cuts to Medicaid could be devastating for nursing home residents13·12 days agoYou act like 100% of old people voted trump. They favored him 52 to 47 according to the AARP.
I understand you are angry, but just being blindly mad at a group of people due to prejudice and stereotyping is not ok. It’s exactly what the Republicans are doing with trans and brown people. You are no better than them.
normalexit@lemmy.worldto News@lemmy.world•"Big, beautiful bill" cuts to Medicaid could be devastating for nursing home residents14·12 days agoDisadvantaged old people in nursing homes are about to lose their healthcare, bankrupt their families, and die horrible deaths.
It’s not whomp whomp unless you are a sociopath.
Billionaires are to blame. This is a class war. I don’t want to sacrifice human beings for tax cuts regardless of how they may have voted.
Whelp, sorry about messing up your habitat. Here’s some garbage… Looks like our job here is done.
normalexit@lemmy.worldto News@lemmy.world•Musk threatens to primary members of Congress who vote for Trump's megabill3·14 days agoMy brain in a sleepy state injected the word “Republican” in the title. Lol, oops.
normalexit@lemmy.worldto News@lemmy.world•Musk threatens to primary members of Congress who vote for Trump's megabill121·14 days agoSo almost all of them?
The monkey at the keyboard thinking is what software development is. When faced with a failing test, you make it pass as simply as possible, and then you summon all your computer science / programming experience to refactor the code into something more elegant and maintainable.
In this case that is using math to check if the input is divisible by two without a remainder. If you don’t know how that works, you’re going to have a bad time, like the picture in this post.
TDD doesn’t promise to drive the final implementation at the unit level, but it does document how the class under test behaves and how to use it.