Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

TooMuchAbstraction posted:

When you think about it, the real horror is trusting computers with anything important, considering how often we find software to be such a shitshow.

Computers and people too.

Adbot
ADBOT LOVES YOU

QuarkJets
Sep 8, 2008

TooMuchAbstraction posted:

When you think about it, the real horror is trusting computers with anything important, considering how often we find software to be such a shitshow.

Can't wait for smart contracts!

Spatial
Nov 15, 2007

32-byte bytes for all

Nippashish
Nov 2, 2005

Let me see you dance!

QuarkJets posted:

Can't wait for smart contracts!

Have you heard the word of the blockchain, my dude?

chutwig
May 28, 2001

BURLAP SATCHEL OF CRACKERJACKS

TooMuchAbstraction posted:

When you think about it, the real horror is trusting computers with anything important, considering how often we find software to be such a shitshow.

I agree. Working in tech and writing software makes me trust this stuff less, not more, because I know how janky it probably all is under the hood. I probably have some built-in luddite tendencies as well - my co-workers all talk about the latest IoT stuff they’ve installed in their house, but I still set the temperature by hand on my Honeywell thermostat and buy paper bus tickets. I’m sure eventually I’ll add some sort of home automation stuff or a Nest or whatever, but the threshold at which I will consider such things is pretty high.

Mr Shiny Pants
Nov 12, 2012

chutwig posted:

I agree. Working in tech and writing software makes me trust this stuff less, not more, because I know how janky it probably all is under the hood. I probably have some built-in luddite tendencies as well - my co-workers all talk about the latest IoT stuff they’ve installed in their house, but I still set the temperature by hand on my Honeywell thermostat and buy paper bus tickets. I’m sure eventually I’ll add some sort of home automation stuff or a Nest or whatever, but the threshold at which I will consider such things is pretty high.

This, when I think of all the libraries that are in use by companies that just want to make money and don't give a gently caress about the software........

NihilCredo
Jun 6, 2011

iram omni possibili modo preme:
plus una illa te diffamabit, quam multæ virtutes commendabunt

QuarkJets posted:

Can't wait for smart contracts!

Hey, don't diss smart contracts. Name another software that comes with automatic built-in bug bounties :v:

EssOEss
Oct 23, 2006
128-bit approved

Hammerite posted:

How do you respond to the discussion on this page?

The way I see it, interactions in a highly connected timezoneless world depend on the recipient's presence most of all. It is up to Uncle Joe to set his phone to silent mode if he does not wish to receive calls. He can choose his own presence and live on the schedule he likes, synchronizing it with people only when getting real-time contact it matters to him (hey bro call me between 0800 and 0900 - and nobody cares where the sun is), leaving it for his technological servants to deal with otherwise.

Ranzear
Jul 25, 2013

Master_Odin posted:

Well, for me, I personally hate functions that both mutate their parameters and returns a status flag on completion, especially since this is within a class where you could save data to a class variable. I'd also probably just put all three functions into a try/catch since the point was to quit on error (which shouldn't happen almost ever in production).

I've since learned he's done a switch(false) elsewhere to do form validation and in the default clause another switch(false) that handles DB interactions.

If you want to nip this in the bud, I have a slightly less egregious pattern to suggest for "bail-out" chaining:

code:
$success = true;
do {
	if (!function()) {
		logjunk();
		$success = false;
		break;
	} else if (!otherfunction()) {
		$success = false;
		logjunk();
		break;
	} [...]
} while (true);
if ($success) {
	/* Do regular stuff */
} else {
	/* Do error-case stuff */
}
But really, roll your own exception class that fails gently and writes to your own logs and use throw as a break.

Ranzear fucked around with this message at 19:06 on Aug 23, 2017

Gazpacho
Jun 18, 2004

by Fluffdaddy
Slippery Tilde

Master_Odin posted:

Well, for me, I personally hate functions that both mutate their parameters and returns a status flag on completion, especially since this is within a class where you could save data to a class variable. I'd also probably just put all three functions into a try/catch since the point was to quit on error (which shouldn't happen almost ever in production).

I've since learned he's done a switch(false) elsewhere to do form validation and in the default clause another switch(false) that handles DB interactions.
Perhaps I've misunderstood but it sounds like you want to track method failures in a manner that isn't reentrant. Which isn't necessarily out of the question, but does bring its own problems.

Ranzear posted:

If you want to nip this in the bud, I have a slightly less egregious pattern to suggest for "bail-out" chaining:
Just use a goto already, you know you want to. :twisted:

Gazpacho fucked around with this message at 19:29 on Aug 23, 2017

Ranzear
Jul 25, 2013

Gazpacho posted:

Just use a goto already, you know you want to. :twisted:

Back when I wrote my first PHP login script, you wouldn't have been wrong.

Real solution is more like:
code:
try {
	if (!function())
		throw new CustomLoggerException("function failed", FUNCTION_ERRORCODE, $extralogdata);
	else if (!otherfunction())
		throw new CustomLoggerException("other function failed", OTHER_FUNCTION_ERRORCODE, $extralogdata);
} catch (Exception $e) {
	throw new CustomLoggerException("Thing went boom", $e->getCode(), $extralogdata, $e->getMessage());
} catch (CustomLoggerException $e) {
}	// Custom exception did all the work already
Notice it chains other exceptions into the custom handler with optional args to put them into the same log file, so you can see what went wrong in your own log but also if it was caused by something not yours.

The Phlegmatist
Nov 24, 2003
I'm maintaining Ruby code that uses continuations.

My advice is to never use continuations. Particularly when the language barely supports them. What happens when you throw an exception in the middle of your continuation? Who knows, we're just gonna do it and be legends.

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

Gazpacho posted:

Just use a goto already, you know you want to. :twisted:

Proposition - of the very few cases where "goto" is an acceptable tool for the job, all are cases where the label is (a) within the same method, (b) in the same scope as the "goto" or in a parent scope, (c) "forwards" within the method (i.e. to a later line)*. Goto implementations should therefore ideally be restricted to work in this way.

I'd be interested to see counterexamples (and I realise that the status of a volunteered use case as a counterexample is dependent on my inclination to view said use case as one where goto is "an acceptable tool for the job" and that this description is very vague and subjective)

* It follows that goto plus conditional statements would not be sufficient to allow looping, in the absence of loop control structures or recursion

FlapYoJacks
Feb 12, 2009

Ranzear posted:

If you want to nip this in the bud, I have a slightly less egregious pattern to suggest for "bail-out" chaining:

code:
$success = true;
do {
	if (!function()) {
		logjunk();
		$success = false;
		break;
	} else if (!otherfunction()) {
		$success = false;
		logjunk();
		break;
	} [...]
} while (true);
if ($success) {
	/* Do regular stuff */
} else {
	/* Do error-case stuff */
}
But really, roll your own exception class that fails gently and writes to your own logs and use throw as a break.

A do while loop? You MONSTER.

sarehu
Apr 20, 2007

(call/cc call/cc)
I think a counter example is the odd method you might think is most naturally representable with tail recursion. But since your language doesn't have tail recursion you have a goto to the top of the function.

Another might be, I don't know, if you really really wanted to have two entry points into a loop. I have a vague categorical notion that I wanted this once, but I forget why.

Another might be to skip a conditional check you know will be true in the future. You could control flow right into it, but hey, performance. So you jump right into the nested scope. I've had occasion to say, hey, I could do that, but I've never really needed it or done it.

Another example is where you reach a point in your computation that the right thing to do is to "retry." Well, that might not be best represented as a loop for some reason. I've never seen a solitary goto statement make a function more confusing.

Carbon dioxide
Oct 9, 2012

Not really a horror, but this site is quite something.

https://sidewaysdictionary.com/

canis minor
May 4, 2011

Carbon dioxide posted:

Not really a horror, but this site is quite something.

Autocomplete posted:

It’s like every bar in the world is your local. You go to order a drink, the staff make a lightning quick judgment based on your location, the most popular orders at that time of day, and the shape your mouth is forming as you begin to speak. Before you know it, a margarita awaits. The bar in this case is a search bar.

:pusheen:

Workaday Wizard
Oct 23, 2009

by Pragmatica

Cybercrime posted:

It’s like the law of the horse. In the early days of the internet, a US judge argued against the idea of a separate field of ‘cyberlaw’ by comparing it to laws for horses. There are many crimes that involve horses, just as there are many that involve computers, but ‘horse law’ isn’t a separate field in its own right – which is a shame, as it sounds like fun.

SupSuper
Apr 8, 2009

At the Heart of the city is an Alien horror, so vile and so powerful that not even death can claim it.
Posted verbatim:

C# code:
try
{
	if (this.init_)
	{
	}
}
catch
{
	//nop
}
Makes you think, doesn't it.

Vanadium
Jan 8, 2005

I'm the coding horror because after a long slippery slope of preferring infinite loops with explicit if(...)break; over regular loops if the latter would involve the slightest extra contortion, I'm increasingly catching myself wishing for local jumps in high-level langs and thinking about how many extra control vars I could elide if I my code just consisted of a mostly unstructured set of blocks connected by arbitrary control flow edges.

CPColin
Sep 9, 2003

Big ol' smile.
Something like 2.5 weeks into my new job, I got my first look at a small bit of the code. It's a utility class that's 2,077 lines long and has an 818-line method in it that's one giant switch statement. There's also a bunch of stuff that was clearly copied and pasted. Good target for refactoring, right? Well, too bad, because there's no test coverage, as far as I can tell!

TooMuchAbstraction
Oct 14, 2012

I spent four years making
Waves of Steel
Hell yes I'm going to turn my avatar into an ad for it.
Fun Shoe

CPColin posted:

Something like 2.5 weeks into my new job, I got my first look at a small bit of the code. It's a utility class that's 2,077 lines long and has an 818-line method in it that's one giant switch statement. There's also a bunch of stuff that was clearly copied and pasted. Good target for refactoring, right? Well, too bad, because there's no test coverage, as far as I can tell!

Congrats, you're now the code quality champion. Have fun convincing everyone else they're doing it wrong.

ChaosArgate
Oct 10, 2012

Why does everyone think I'm going to get in trouble?

CPColin posted:

Something like 2.5 weeks into my new job, I got my first look at a small bit of the code. It's a utility class that's 2,077 lines long and has an 818-line method in it that's one giant switch statement. There's also a bunch of stuff that was clearly copied and pasted. Good target for refactoring, right? Well, too bad, because there's no test coverage, as far as I can tell!

Same, except I was about 9 hours into my job.

Ranzear
Jul 25, 2013

ratbert90 posted:

A do while loop? You MONSTER.

"slightly less egregious"

Nobody noticed I put 'while(true)' instead of 'while(false)' though, even myself :v:

Vanadium posted:

I'm increasingly catching myself wishing for local jumps in high-level langs and thinking about how many extra control vars I could elide if I my code just consisted of a mostly unstructured set of blocks connected by arbitrary control flow edges.

I'm concerned that you phrase it this way instead of 'I should put things in functions and call them from a main flow control.'

Ranzear fucked around with this message at 00:15 on Aug 25, 2017

canis minor
May 4, 2011

ChaosArgate posted:

Same, except I was about 9 hours into my job.

I guess everybody's first, second, third, fourth, or current job is like that.

lifg
Dec 4, 2000
<this tag left blank>
Muldoon

CPColin posted:

Something like 2.5 weeks into my new job, I got my first look at a small bit of the code. It's a utility class that's 2,077 lines long and has an 818-line method in it that's one giant switch statement. There's also a bunch of stuff that was clearly copied and pasted. Good target for refactoring, right? Well, too bad, because there's no test coverage, as far as I can tell!

Best part is when you discover that one code path is just impossible to reach. Second best part is when you tell your boss about it, and he says, "That's a pretty important piece of functionality. Weird!"

Steve French
Sep 8, 2003

CPColin posted:

Something like 2.5 weeks into my new job, I got my first look at a small bit of the code. It's a utility class that's 2,077 lines long and has an 818-line method in it that's one giant switch statement. There's also a bunch of stuff that was clearly copied and pasted. Good target for refactoring, right? Well, too bad, because there's no test coverage, as far as I can tell!

It took you 2.5 weeks to even see some code?

That might actually be more concerning

baquerd
Jul 2, 2007

by FactsAreUseless

Steve French posted:

It took you 2.5 weeks to even see some code?

That might actually be more concerning

Weird clearances aside, yeah that's super concerning if you're expected to code.

Mezzanine
Aug 23, 2009
I so want to see that utility class

CPColin
Sep 9, 2003

Big ol' smile.
People keep being on vacations and we had a week of Scrum training that we promptly took to heart. For example: we just started a three-week sprint by having a three-hour sprint planning meeting that started with an hour of backlog refinement, because the PO hadn't done any of that yet.

NihilCredo
Jun 6, 2011

iram omni possibili modo preme:
plus una illa te diffamabit, quam multæ virtutes commendabunt

Vanadium posted:

I'm the coding horror because after a long slippery slope of preferring infinite loops with explicit if(...)break; over regular loops if the latter would involve the slightest extra contortion, I'm increasingly catching myself wishing for local jumps in high-level langs and thinking about how many extra control vars I could elide if I my code just consisted of a mostly unstructured set of blocks connected by arbitrary control flow edges.

Sounds like you want a finite state machine tbh.

leper khan
Dec 28, 2010
Honest to god thinks Half Life 2 is a bad game. But at least he likes Monster Hunter.

CPColin posted:

People keep being on vacations and we had a week of Scrum training that we promptly took to heart. For example: we just started a three-week sprint by having a three-hour sprint planning meeting that started with an hour of backlog refinement, because the PO hadn't done any of that yet.

Sounds like my experience with most shops that do "agile". Current place will occasionally cancel planning meetings the day of because the PO is OOO as well.

SupSuper
Apr 8, 2009

At the Heart of the city is an Alien horror, so vile and so powerful that not even death can claim it.

CPColin posted:

Something like 2.5 weeks into my new job, I got my first look at a small bit of the code. It's a utility class that's 2,077 lines long and has an 818-line method in it that's one giant switch statement. There's also a bunch of stuff that was clearly copied and pasted. Good target for refactoring, right? Well, too bad, because there's no test coverage, as far as I can tell!
I haven't experienced a workplace with tests yet. :(

john donne
Apr 10, 2016

All suitors of all sorts themselves enthral;

So on his back lies this whale wantoning,

And in his gulf-like throat, sucks everything

That passeth near.

SupSuper posted:

I haven't experienced a workplace with tests yet. :(

Write them yourself.

CPColin
Sep 9, 2003

Big ol' smile.
In a method annotated [Test] that is not an actual automated test, but rather is run by hand as part of manual testing:

code:
try
{
    (bunch of stuff)
}
catch
{
    throw;
}
Uh, I'm not sure that catch is very useful.

Edit: There's an empty catch block in another one of these "tests," so it always "passes."

porksmash
Sep 30, 2008

SupSuper posted:

I haven't experienced a workplace with tests yet. :(

I just got my entire group to start writing unit tests. We were stuck in a catch-22 of crushing piles of work to do, but a lot of it was fixing bugs that made it into production. The general attitude was "we dont have time to write tests" but anyone who's actually written tests knows it saves time in the end. So, I just started writing tests. My code was then the most bug-free code. People noticed and wanted the same thing, and there you have it.

It was like a sea-change in everyone's perception of how to write code. Everyone is gung-ho about reducing the number of dependencies, writing testable code instead of monolithic monstrocities, taking pride in how many tests they write. It's honestly amazing and you just have to make it happen yourself sometimes.

lifg
Dec 4, 2000
<this tag left blank>
Muldoon
"Be the change you wish to see in the world."

-Gandhi

Bongo Bill
Jan 17, 2012

porksmash posted:

I just got my entire group to start writing unit tests. We were stuck in a catch-22 of crushing piles of work to do, but a lot of it was fixing bugs that made it into production. The general attitude was "we dont have time to write tests" but anyone who's actually written tests knows it saves time in the end. So, I just started writing tests. My code was then the most bug-free code. People noticed and wanted the same thing, and there you have it.

It was like a sea-change in everyone's perception of how to write code. Everyone is gung-ho about reducing the number of dependencies, writing testable code instead of monolithic monstrocities, taking pride in how many tests they write. It's honestly amazing and you just have to make it happen yourself sometimes.

Are you just writing tests, or going full TDD?

TooMuchAbstraction
Oct 14, 2012

I spent four years making
Waves of Steel
Hell yes I'm going to turn my avatar into an ad for it.
Fun Shoe

Bongo Bill posted:

Are you just writing tests, or going full TDD?

TDD is the same thing as writing testable code, and then writing tests for that code. Whether you write the tests before the code or the other way around, the important thing is that you write the code with testing in mind.

Adbot
ADBOT LOVES YOU

Bongo Bill
Jan 17, 2012

TooMuchAbstraction posted:

TDD is the same thing as writing testable code, and then writing tests for that code. Whether you write the tests before the code or the other way around, the important thing is that you write the code with testing in mind.

I don't agree with the definition of the term. Writing the tests first is an important part of the practice as I understand it. There are other parts, too.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply