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
Joda
Apr 24, 2010

When I'm off, I just like to really let go and have fun, y'know?

Fun Shoe

hexate posted:

A perennial favorite of mine - pure, undistilled fuckery. This if continues into a business logic pyramid of doom...

code:

	String property = getString(PROPERTY_NAME);
	//if property is allowed.
	if(property.equals("DISALLOW")
	{

Is the comment wrong? Is the conditional wrong? Or is this some sick joke where "DISALLOW" means allowed?

Every customer has their own opinion. This gem was written a decade ago, and both the product owner and developer have long since moved on

What really gets me here is that I expect 'getString' to give me a string representation of the property value or property name. Definitely would not expect it to give me a string expressing whether or not it's allowed in whatever context.

Adbot
ADBOT LOVES YOU

hexate
Sep 13, 2012

What do you mean it's not Tom Cruise?

Even better, there are only two expected states for the property anyway, and yet, its stored AND interpreted as a string...

HappyHippo
Nov 19, 2003
Do you have an Air Miles Card?
Yet another example of "stringly typed" code

Bruegels Fuckbooks
Sep 14, 2004

Now, listen - I know the two of you are very different from each other in a lot of ways, but you have to understand that as far as Grandpa's concerned, you're both pieces of shit! Yeah. I can prove it mathematically.

hexate posted:

A perennial favorite of mine - pure, undistilled fuckery. This if continues into a business logic pyramid of doom...

code:

	String property = getString(PROPERTY_NAME);
	//if property is allowed.
	if(property.equals("DISALLOW")
	{

Is the comment wrong? Is the conditional wrong? Or is this some sick joke where "DISALLOW" means allowed?

Every customer has their own opinion. This gem was written a decade ago, and both the product owner and developer have long since moved on

I only read comments if they're good. If they're stupid (like that one), code wins. I've worked on codebases where primary developers were Japanese speakers, and the comments were in Japanese, and frankly I didn't miss being able to read comments at all.

Ola
Jul 19, 2004

Maybe an example of code getting updated but not comments.

hexate
Sep 13, 2012

What do you mean it's not Tom Cruise?

Ola posted:

Maybe an example of code getting updated but not comments.

I had hoped so too, but both lines were added in the same commit!

JawnV6
Jul 4, 2004

So hot ...

Dylan16807 posted:

I don't know how I can be clearer than "You don't change the CAN communication. It already works." :shrug:
You're being nonsensical. I'd like to understand what you're proposing, but your vast ignorance is precluding a good faith discussion. Does CAN require an in-band ACK/NACK differentiation? This question is central to answering if we can add your data diode "outside CAN" or not, and your indifference to the details yet again takes front and center as you decline to even appreciate the question's importance.

I gave an example of where "don't change the $protocol communication" is literally impossible to do, there are in-band situations that require agent participation to signal state. I'm asking if CAN is similar in this respect, in which case "don't change the CAN communication it already Works" is electrically impossible to achieve. But since you're too dumb to clock the question you retreat to the dumb bullshit you've been peddling, acting as if this distance from the problem is a virtue instead of precluding any such solution.

iospace posted:

We get it dude, you've worked on it.

Now are you capable of responding without being a jackass? Looks like that answer is no.
Actually I haven't in depth, I'm just miles closer than some DBA who's never glanced at a schematic or bothered to expand COGS. He's not even pretending to understand the domain or even the solution he's proposing, sticking with a garbage answer that's wholly inappropriate.

Why is it y'all think I'm being a jackass? I'm boiling this down to trivial yes/no questions that an honest read of Wikipedia would answer conclusively. You'd genuinely prefer the ignorant poster shooting from the hip here in the *checks notes* Coding Horror thread?

dick traceroute
Feb 24, 2010

Open the pod bay doors, Hal.
Grimey Drawer

JawnV6 posted:

Why is it y'all think I'm being a jackass?

Your posts

Dylan16807
May 12, 2010

JawnV6 posted:

You're being nonsensical. I'd like to understand what you're proposing, but your vast ignorance is precluding a good faith discussion. Does CAN require an in-band ACK/NACK differentiation? This question is central to answering if we can add your data diode "outside CAN" or not, and your indifference to the details yet again takes front and center as you decline to even appreciate the question's importance.

I gave an example of where "don't change the $protocol communication" is literally impossible to do, there are in-band situations that require agent participation to signal state. I'm asking if CAN is similar in this respect, in which case "don't change the CAN communication it already Works" is electrically impossible to achieve. But since you're too dumb to clock the question you retreat to the dumb bullshit you've been peddling, acting as if this distance from the problem is a virtue instead of precluding any such solution.

Actually I haven't in depth, I'm just miles closer than some DBA who's never glanced at a schematic or bothered to expand COGS. He's not even pretending to understand the domain or even the solution he's proposing, sticking with a garbage answer that's wholly inappropriate.

Why is it y'all think I'm being a jackass? I'm boiling this down to trivial yes/no questions that an honest read of Wikipedia would answer conclusively. You'd genuinely prefer the ignorant poster shooting from the hip here in the *checks notes* Coding Horror thread?
I'm not trying to dodge your questions. Let me put it this way: I'm assuming the most difficult case, that the agent needs to actively participate on the network. That's okay, as long as it's controlled purely by ROM.

Pretend we took the existing entertainment unit and disconnected all the buttons and plugs. That is what I mean by "don't change it", in the most godawful prototype form. If you think I'm describing something that's electrically impossible, then there is definitely a misunderstanding.

To continue with the world's worst prototype, while removing the buttons we set it to a debug display that has all the CAN info it needs. Then we build a whole new entertainment unit on top, with a camera to get that info. Screen to camera is the data diode.

The next step is replacing screen->camera with a single wire. Then we remove 90% of the parts in the inner unit because they're not doing anything any more.

Now we have a single compact entertainment unit, where one sub-circuit does things on the network autonomously, and it's impossible for button presses to affect it.

I like the idea of a database analogy. Because even someone who has never touched a database can say "Hey, this query is what we need. We could make a cron job that does that query and puts the results in a file. That way no matter how badly our application gets compromised, it can't change the database query." It's not necessarily a good solution, but it would do the job.

Dylan16807 fucked around with this message at 23:15 on May 13, 2019

JawnV6
Jul 4, 2004

So hot ...
if you're not trying to duck the questions, wanna take a whack at these unanswered gems

JawnV6 posted:

do the CAN systems you've worked with NACK for any reason other than a CRC mismatch? can that information be shuffled back and forth across the data diode you've selected for this application? what would the failure mode be if the CAN node didn't respect this area of the protocol?

do you let yokels from unaffiliated disciplines give you notes on the digital systems you design? why or why not?

JawnV6 posted:

Does CAN require an in-band ACK/NACK differentiation?
i seriously boiled it down as much as i could and put the direct question right to you, and i can't find a simple yes/no answer to these basic questions

i'm not engaging with yet another whack at handwaving furiously and verbosely enough to hide the fact you don't know this fundamental question

Dylan16807
May 12, 2010

JawnV6 posted:

if you're not trying to duck the questions, wanna take a whack at these unanswered gems


i seriously boiled it down as much as i could and put the direct question right to you, and i can't find a simple yes/no answer to these basic questions

i'm not engaging with yet another whack at handwaving furiously and verbosely enough to hide the fact you don't know this fundamental question
Reasons for NACK: Doesn't matter, I'll assume the worst case that it can, but the existing code already handles that. Can information be shuffled back and forth: Yes, otherwise how would the system already work? What would the failure mode be: The same as if the existing system failed, but now the user can't be the cause. Do I let yokels offer advice on what I design: yes. Can it require in-band differentiation: Doesn't matter, I'll assume the worst case that it can, but the existing code already handles that.

Would you please explain how ripping out all the buttons and user-accessible ports from the entertainment system wouldn't make it hack-proof, and a garbage but functional data diode?

I'm not suggesting that as a finished solution. It's an example to show that "electrically impossible" is you talking past me, and refuting an imaginary argument. It doesn't matter that I don't know much about CAN. I made an argument that works for any network.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
The right answer is to not try and put a data diode on the can bus, instead you give the entertainment unit a separate component for talking to the bus and put your data diode in between that and the entertainment unit proper. (Hell, you might have that separation already, presuming you're not piping your 100V transients directly into your entertainment unit processor). (You might not even need an explicit diode component, if the interface for talking between the two parts only allows for one-way communication). Which I think is what Dylan is trying to get at, but it's not really obvious from the initial "stick a data diode on it".

This scheme does fall apart in other ways once you start wanting the entertainment unit to be able to send some types of messages but not others.

Cuntpunch
Oct 3, 2003

A monkey in a long line of kings
"Since we're using that name like that for a property that exists but we want to deserialize into a different property, we need to flag this one to be ignored" I say last week.
Today, a request to code review.

code:
[JsonProperty("@JsonIgnore")]
"That looks...weird." I say. "Does the @ have some special meaning in JSON.NET that I was unfamiliar with?"

My colleague smirks. "It works." he says.

"Sure but does it work...on accident or by design?"

He rolls his eyes slightly. "I didn't make this up, it's from an answer on StackOverflow." His tone suggests this proves something.

He pulls up the tab with the SO answer and scrolls through the various code snippets. Almost immediately, my eyes see it:

code:
public class Something{
    @JsonIgnore
    public int someThing;
}
He finishes scrolling. "It's somewhere on here."

"Why are we looking at Java code?" I ask.

He pauses. Looks up. Looks away. Looks at the screen. Looks away. Looks at me.

"Well, it's probably one library that uses common code."

"Between Java and C#?"

Looks up. Looks away. Looks up. Looks away.

"I mean. It could."

redleader
Aug 18, 2005

Engage according to operational parameters
LGTM, ship it.

JawnV6
Jul 4, 2004

So hot ...

Dylan16807 posted:

Reasons for NACK: Doesn't matter, I'll assume the worst case that it can, but the existing code already handles that. Can information be shuffled back and forth: Yes, otherwise how would the system already work? What would the failure mode be: The same as if the existing system failed, but now the user can't be the cause. Do I let yokels offer advice on what I design: yes.
a NACK on a CAN bus is a write. if you have the ability to NACK on command, you can write a pattern such that other agents would interpret it as a command. again, i've been insisting that the details matter, you calmly/ignorantly assume they don't, now here we are. the "data diode" at various parts of your unhinged handwaving solution is capable of shuffling the NACK back towards the CAN, and welp that's arb write access oopsie! you've either designed a complex system that still allows the entertainment unit arbitrary writes, or you're handwaving so furiously you don't care about the massive gap. since we don't know if a NACK is a system-critical thing, i look forward to you saying we don't need them at all, at which point we can discuss that unique failure mode.

Dylan16807 posted:

Can it require in-band differentiation: Doesn't matter, I'll assume the worst case that it can, but the existing code already handles that.
the entire loving point is you don't trust the "existing code" and just saying "existing code already handled!" means you're giving that write access to the agent we're considering a threat? again, if you had half a loving clue what your proposed threat model even was it would really help us both out

Dylan16807 posted:

Would you please explain how ripping out all the buttons and user-accessible ports from the entertainment system wouldn't make it hack-proof, and a garbage but functional data diode?
my entertainment system has radios. does yours have radios? radios can allow software access without a user-accessible button, again this is table stakes for EE design but wholly unknown in the DBA world i guess. it wouldn't make it, to use this amazing term you've got here, "hack-proof" in any sense

do you think people are hacking cars by TAS'ing konami codes into the head unit buttons? is that the only possible threat model you've considered? christ this is a farce

Dylan16807 posted:

I'm not suggesting that as a finished solution. It's an example to show that "electrically impossible" is you talking past me, and refuting an imaginary argument. It doesn't matter that I don't know much about CAN. I made an argument that works for any network.
you don't know enough about the protocol to make sensible designs. you're convinced this doesn't impede your solution from being viable and will continue asserting this falsehood despite any attempts to implore you to take the slightest peek under the hood

in network terms, if i send out a packet and don't hear a response, is a reasonable solution to re-send the packet? if i send out "volume up" and don't hear back (because you lopped off the entertainment unit) what happens if the button tries to re-send? could it possibly block other more critical communications from occurring?

Jabor posted:

This scheme does fall apart in other ways once you start wanting the entertainment unit to be able to send some types of messages but not others.
as hardcore as this poster's flubbing EE alone, i wouldn't start to put systems questions in front of them

RPATDO_LAMD
Mar 22, 2013

🐘🪠🍆

Obviously what he is saying is that the piece of hardware in a car radio in charge of reading data from the CAN and sending ACK/NACK messages should be segregated from the piece of hardware in charge of running the buttons and radio antenna. You are free to design the internal communication between these two components of your radio in any way since it does not affect the external interface that the rest of the vehicle sees.
The CAN-talk-to-er chip unavoidably has write access if it is connected to the network, but the radio proper does not need to (and should not) have write access to its CAN-talk-to-er.

GABA ghoul
Oct 29, 2011

Saw this gem today

code:

if(someList.Count <= 0)

:wtc:

Dylan16807
May 12, 2010

RPATDO_LAMD posted:

Obviously what he is saying is that the piece of hardware in a car radio in charge of reading data from the CAN and sending ACK/NACK messages should be segregated from the piece of hardware in charge of running the buttons and radio antenna. You are free to design the internal communication between these two components of your radio in any way since it does not affect the external interface that the rest of the vehicle sees.
The CAN-talk-to-er chip unavoidably has write access if it is connected to the network, but the radio proper does not need to (and should not) have write access to its CAN-talk-to-er.
Yes, this.

JawnV6 posted:

the entire loving point is you don't trust the "existing code" and just saying "existing code already handled!" means you're giving that write access to the agent we're considering a threat?
This is the core of the misunderstanding. An agent that can't get input from outside the CAN bus is not a threat. The purpose of the data diode is to keep the agent away from the outside world.

In loose terms, this is a data diode "attached to" the CAN bus via the agent. In more precise terms you have a sequence of CAN<->agent->diode->rest of the entertainment unit.

JawnV6 posted:

radios can allow software access without a user-accessible button
Ugh, sorry I didn't nitpick the post enough, I had 'radios' written at one point but I tried to simplify, that's supposed to be covered under "ports and buttons".

JawnV6 posted:

do you think people are hacking cars by TAS'ing konami codes into the head unit buttons? is that the only possible threat model you've considered? christ this is a farce
That's why I said "ports".

JawnV6 posted:

in network terms, if i send out a packet and don't hear a response, is a reasonable solution to re-send the packet? if i send out "volume up" and don't hear back (because you lopped off the entertainment unit) what happens if the button tries to re-send? could it possibly block other more critical communications from occurring?
In the "absolutely secure" model, those packets are not allowed. Volume needs to be handled entirely inside the entertainment unit.

Dylan16807 fucked around with this message at 21:41 on May 14, 2019

Peewi
Nov 8, 2012

Opferwurst posted:

Saw this gem today

code:
if(someList.Count <= 0)
:wtc:

You know, in case it's very empty.

Volguus
Mar 3, 2009

Opferwurst posted:

Saw this gem today

code:
if(someList.Count <= 0)
:wtc:

Other than the less than being useless, what are the other problems with this code? What does Count return? int? uint? size_t?

Xik
Mar 10, 2011

Dinosaur Gum
32 bit signed int, but it won't be less than zero. I'd argue it's really not a coding "horror", just has some redundancy. I would be generous and just say the author was used to being explicit elsewhere and just did it here without really thinking. someList could also be null so it can throw a null exception when checking count if it hasn't been checked yet.
I would just do (or the inverse):
code:
if someList?.Any()
Because it reads better. There is a perf hit but lmao at caring about this level of optimization.

Hammerite
Mar 9, 2007

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

Peewi posted:

You know, in case it's very empty.

A biologist, a physicist and a mathematician sit in a cafe one morning and observe the office building over the road. They see two people arrive, unlock the doors and go inside. A few minutes later, to their surprise they see four people leave the building.

"Ah", says the biologist, "they have reproduced".

The physicist shrugs. "There's no problem here", he says, "the observations weren't accurate enough".

The mathematician remarks, "If two more people go into the building, it will be empty again."

Volguus
Mar 3, 2009

Xik posted:

32 bit signed int, but it won't be less than zero. I'd argue it's really not a coding "horror", just has some redundancy. I would be generous and just say the author was used to being explicit elsewhere and just did it here without really thinking. someList could also be null so it can throw a null exception when checking count if it hasn't been checked yet.
I would just do (or the inverse):
code:
if someList?.Any()
Because it reads better. There is a perf hit but lmao at caring about this level of optimization.

Personally I believe that Empty() would read better than Any, but that's neither here or there. Checking for "Count <= 0", especially when said Count returns a signed value just screams of defensive programming. You never know when the value could potentially overflow, when a bug in that list implementation may return -1, when radiation from the sun will flip a bit. Since I have a hard time believing that "== 0" is more efficient than "<= 0" I would almost always prefer the "<= 0" if something like "Empty" is not available.

nielsm
Jun 1, 2009



I don't like Empty() as a method name for checking for collection being empty. It reads just as much as a verb, the boolean method should be named IsEmpty().

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
If something completely and utterly unexpected by the programmer has happened, your code should crash loudly and messily rather than trying to carry on as best it can.

If your data has been corrupted by a random bit-flip, carrying on as though nothing has happened is likely to be the worst possible option!

OddObserver
Apr 3, 2009

Jabor posted:

If something completely and utterly unexpected by the programmer has happened, your code should crash loudly and messily rather than trying to carry on as best it can.

If your data has been corrupted by a random bit-flip, carrying on as though nothing has happened is likely to be the worst possible option!

The real fun stuff is when your code gets corrupted by a random bit-flip.

Volguus
Mar 3, 2009

Jabor posted:

If something completely and utterly unexpected by the programmer has happened, your code should crash loudly and messily rather than trying to carry on as best it can.

If your data has been corrupted by a random bit-flip, carrying on as though nothing has happened is likely to be the worst possible option!

In this particular case one can argue: I don't really give a drat about the "why's", all that i care about is that i do not have zero (or less) elements in the list. Adding an assert or another check for the completely off the wall return values is of course another possibility. Now, if benchmarking would show that <= is slower than ==, then sure, by all means ban the use of "<=".

Xarn
Jun 26, 2015
If the size is < 0, you should hard crash right now.

Volguus
Mar 3, 2009

Xarn posted:

If the size is < 0, you should hard crash right now.

For some applications this is certainly the only correct move. For most people/domains/applications out there an acceptable answer is to go on and just ignoring crap like that (especially when that list will probably get garbage collected soon) which is most likely caused by a weird library bug. Of course, YMMV.

Edit: This is a silly argument to have. If I would see this code in a project that I'm working on, I'll probably just shrug it off. It's a "meh" at most. But I can see why it can rub some people off in the wrong way.

Volguus fucked around with this message at 14:50 on May 15, 2019

DaTroof
Nov 16, 2000

CC LIMERICK CONTEST GRAND CHAMPION
There once was a poster named Troof
Who was getting quite long in the toof

Volguus posted:

In this particular case one can argue: I don't really give a drat about the "why's", all that i care about is that i do not have zero (or less) elements in the list. Adding an assert or another check for the completely off the wall return values is of course another possibility. Now, if benchmarking would show that <= is slower than ==, then sure, by all means ban the use of "<=".

What if the programmer wants to check if the list is empty, and count < 0 doesn't mean the list is empty because the integer overflowed?

As for the code in question, my first guess was that the programmer had tried something like count <= 1 while troubleshooting a fencepost error, and eventually settled on 0 without changing the operator.

dougdrums
Feb 25, 2005
CLIENT REQUESTED ELECTRONIC FUNDING RECEIPT (FUNDS NOW)

Volguus posted:

Other than the less than being useless, what are the other problems with this code? What does Count return? int? uint? size_t?
Count returns an int, so I can see them thinking that in some bizarre circumstance < 0 is a possibility so might as well. But this is already enforced within the class:
code:
public int Count { get { Contract.Ensures(Contract.Result<int>() >= 0); return _size; } } 
https://referencesource.microsoft.com/mscorlib/a.html#78a69d857716bc68

The Any() extension method exists for this purpose though, unless you're cursed to work on something so old that you can't use linq.

Not really a horror, but it invites the opportunity to make a mistake by accidentally writing list.Count < 0.

dougdrums fucked around with this message at 15:21 on May 15, 2019

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



I hadn't seen anyone use .Any() to check for an empty list until I got to my current job and I'm still trying to get used to it :ohdear:

Makes perfect sense, it's just not the idiom I'm used to.

Magissima
Apr 15, 2013

I'd like to introduce you to some of the most special of our rocks and minerals.
Soiled Meat
The real horror is capitalized method names.

taqueso
Mar 8, 2004


:911:
:wookie: :thermidor: :wookie:
:dehumanize:

:pirate::hf::tinfoil:

TBH CANbus is a poor choice for anything that needs security.

AstuteCat
May 4, 2007

Depending on language/implementation, In some cases calling a count() will traverse the list to get the count - if you're trying to see if an enum/list is non-empty, doing an equivalent of 'list != []' might be quicker.

dougdrums
Feb 25, 2005
CLIENT REQUESTED ELECTRONIC FUNDING RECEIPT (FUNDS NOW)

Magissima posted:

The real horror is capitalized method names.

It'd be really hosed up if if I incorrectly assumed that this was C# and it happens to be Java or C++ instead.

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



taqueso posted:

TBH CANbus is a poor choice for anything that needs security.

All's I know is networks is how you get Cylons and I don't want no Cylons in mah car :clint:

Dirt Road Junglist
Oct 8, 2010

We will be cruel
And through our cruelty
They will know who we are

dougdrums posted:

It'd be really hosed up if if I incorrectly assumed that this was C# and it happens to be Java or C++ instead.

Writing Powershell has made me horribly inconsistent about case sensitivity in my code. :sigh:

GABA ghoul
Oct 29, 2011

Volguus posted:

Personally I believe that Empty() would read better than Any, but that's neither here or there. Checking for "Count <= 0", especially when said Count returns a signed value just screams of defensive programming. You never know when the value could potentially overflow, when a bug in that list implementation may return -1, when radiation from the sun will flip a bit. Since I have a hard time believing that "== 0" is more efficient than "<= 0" I would almost always prefer the "<= 0" if something like "Empty" is not available.

:ms:

I asked about it and apparently it's what happens when you use some ReSharper auto refactoring functionality. It inverts a ">0" statement, but isn't smart enough to know that arrays can't have a negative size.

Also, gotta agree that if the fabric of space and time broke down and System.Collections started producing negative sized arrays I would want my program to drop everything and tell me ASAP.

Adbot
ADBOT LOVES YOU

Ola
Jul 19, 2004

Maybe that's what will happen when the Earth's magnetic field flips polarity. :tinfoil:

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