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
Jabor
Jul 16, 2010

#1 Loser at SpaceChem

NihilCredo posted:

I live in the blessed land of GC and exceptions. I thought that unsigned overflow was simply the codification of what would happen by default anyway if unsigned overflow were left as UB. Are there any architectures that need to specifically handle them because they would do weird things otherwise and not guarantee 255 + 2 = 1?

Compilers will often do things like assuming that x + 1 > x is always true. That means they can omit the comparison entirely, ignore all the code that's only reached if that condition is false, etc.

They can't do that if x + 1 can legitimately overflow and be smaller than x.

Adbot
ADBOT LOVES YOU

Happy Thread
Jul 10, 2005

by Fluffdaddy
Plaster Town Cop

Absurd Alhazred posted:

Ah, the OpenGL school of error handling.

Love warning my graphics students 10000 times every year to expect their programs to fail silent on them no matter how hosed up their arrays that they built are, at draw time

KaneTW
Dec 2, 2011

redleader posted:

Gosh, imagine needing to know how many things you have in a collection.

If you have a collection where you need to know the length, you don't use Haskell lists (which are just linked lists). You use Data.Vector or something similar, depending on the other requirements.

Carbon dioxide
Oct 9, 2012

Zopotantor
Feb 24, 2013

...und ist er drin dann lassen wir ihn niemals wieder raus...

Eggnogium posted:

Just lol at the idea that treating < 0 size lists like 0 size lists is defensive programming.

IIRC you can have negative-length lists in Prolog. (It's always Prolog that has the weirdest things.)

"Difference lists" are a hack to speed up operations like list concatenation. A difference list is represented as two parameters to a predicate which normally contain a list and a suffix (potentially uninstantiated) of that list. The pair represents the initial segment of the list up to the start of the suffix.
code:
p([butt, fart], [fart]).  % would be p([butt]) with a simple list

p([fart], [butt, fart]).  % this would be a negative [butt]

iospace
Jan 19, 2038



Put that on my car please.

csammis
Aug 26, 2003

Mental Institution

I have two shirts with this

Hammerite
Mar 9, 2007

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

CPColin
Sep 9, 2003

Big ol' smile.

csammis posted:

I have two shirts with this

Are they equal to each other?

Hammerite
Mar 9, 2007

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

CPColin posted:

Are they equal to each other?

One of them is in NFC and the other is in NFD

Evil_Greven
Feb 20, 2007

Whadda I got to,
whadda I got to do
to wake ya up?

To shake ya up,
to break the structure up!?

Fatty Crabcakes posted:

That's why this is a horror: it's an overly complicated way of doing it wrong.

Imagine if you will someone wanting to do the shockingly complex task of command line arguments that set variables and set logging text for said variables.

Now imagine that the solution to this task is using void pointers and pointer arithmetic from static functions to a shared class.

Apparently, older versions of Visual Studio were more tolerant than more recent VS versions of someone doing this.

Also, the people set to debug this never looked at the compile logs, so it went unfixed for months, using the older compiler version as a patch because 'that one works!'

Evil_Greven fucked around with this message at 00:03 on May 21, 2019

RPATDO_LAMD
Mar 22, 2013

🐘🪠🍆

NihilCredo posted:

I live in the blessed land of GC and exceptions. I thought that unsigned overflow was simply the codification of what would happen by default anyway if unsigned overflow were left as UB. Are there any architectures that need to specifically handle them because they would do weird things otherwise and not guarantee 255 + 2 = 1?

UB is more than just "the compiler doesn't guarantee this". It means "the optimizer is allowed to assume this will never happen and use that assumption to rearrange code and generate slightly faster binaries that explode and fail horribly if it ever actually does."

Unsigned overflow is defined though. It's just signed overflow which is UB.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

Hammerite posted:

One of them is in NFC and the other is in NFD

Did you just tell me to go gently caress myself?

Doom Mathematic
Sep 2, 2008

pokeyman posted:

Did you just tell me to go NFKC myself?

Or something...

megalodong
Mar 11, 2008

RPATDO_LAMD posted:

UB is more than just "the compiler doesn't guarantee this". It means "the optimizer is allowed to assume this will never happen and use that assumption to rearrange code and generate slightly faster binaries that explode and fail horribly if it ever actually does."

Unsigned overflow is defined though. It's just signed overflow which is UB.

https://devblogs.microsoft.com/oldnewthing/?p=633
and the series http://blog.llvm.org/2011/05/what-every-c-programmer-should-know.html

are good discussions of this

Happy Thread
Jul 10, 2005

by Fluffdaddy
Plaster Town Cop

RPATDO_LAMD posted:

Unsigned overflow is defined though. It's just signed overflow which is UB.

Ah, found the answer to this in that second link above. Very cool read

Falcorum
Oct 21, 2010
The lifehack they won't teach you at University: get around all overflow issues by stringly typing your code.

Spatial
Nov 15, 2007

Hardware horror: when you have seven different timer peripherals on a system, and not a single goddamn one of them can generate an interrupt when the time matches a given reference point.

Actually no - one of them can, but it takes 500us to write the reference value, making it completely worthless.

gently caress

Munkeymon
Aug 14, 2003

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



Hello I'm debugging an ActiveX-JS integration in IE in the year of our lord and master satan 2019 please send thoughts and prayers!

taqueso
Mar 8, 2004


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

:pirate::hf::tinfoil:

Spatial posted:

Hardware horror: when you have seven different timer peripherals on a system, and not a single goddamn one of them can generate an interrupt when the time matches a given reference point.

Actually no - one of them can, but it takes 500us to write the reference value, making it completely worthless.

gently caress

What's the hardware?

iospace
Jan 19, 2038


Spatial posted:

Hardware horror: when you have seven different timer peripherals on a system, and not a single goddamn one of them can generate an interrupt when the time matches a given reference point.

Actually no - one of them can, but it takes 500us to write the reference value, making it completely worthless.

gently caress

The worst feeling ever

Remulak
Jun 8, 2001
I can't count to four.
Yams Fan

Spatial posted:

Hardware horror: when you have seven different timer peripherals on a system, and not a single goddamn one of them can generate an interrupt when the time matches a given reference point.

Actually no - one of them can, but it takes 500us to write the reference value, making it completely worthless.

gently caress

:coolfish: you get to solve the problem a different way!

Happy Thread
Jul 10, 2005

by Fluffdaddy
Plaster Town Cop
Oh my god, another left-pad incident

Nolgthorn posted:

https://twitter.com/lukejacksonn/status/1131506699356037121

And then the rover careened into the lunar surface.

Except somehow the remotely depended-upon trivial code was even more trivial:

quote:

console.log('Smarty Smart Smarter');

ultrafilter
Aug 23, 2007

It's okay if you have any questions.


I'm sure someone will get fired over this.

Not anyone who actually deserves it, mind you, but someone will be for sure.

Happy Thread
Jul 10, 2005

by Fluffdaddy
Plaster Town Cop
Here's where the outage was traced back to them:

https://github.com/Unitech/pm2/issues/4289

quote:

Unitech commented 4 days ago
I will provide more information about this GKT package today.

Just to let you know that this allow us to count download, crunch analytics and also have this Dashboard to track downloads: https://map.keymetrics.io/

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe
what's an "optional dependency" anyway

Xerophyte
Mar 17, 2008

This space intentionally left blank

Hammerite posted:

what's an "optional dependency" anyway

Not sure if serious, but: it's a dependency that adds some optional functionality that's not strictly required for your core functionality. For instance, the popular C++ image library OpenImageIO has an optional dependency on the popular C++ font rendering library Freetype. If you include Freetype in your OIIO build then you will produce an OIIO that can load font formats, otherwise it cannot load font formats.

As a concept it's not that uncommon, half the libraries we use at work can be optionally build against TBB if you include that, or optionally target Hexagon DSPs if you include the Hexagon SDK, and so on. Adding dummy dependencies to badly track unspecified user statistics isn't one of the top uses I can think of.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
A dummy dependency is such a pointlessly roundabout "clever" way to gather usage statistics. A npm package can run arbitrary scripts when it's installed and you can just hit your analytics endpoint directly.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
this is compounded by optionalDependencies in npm, actually not being that, lmao

CapnAndy
Feb 27, 2004

Some teeth long for ripping, gleaming wet from black dog gums. So you keep your eyes closed at the end. You don't want to see such a mouth up close. before the bite, before its oblivion in the goring of your soft parts, the speckled lips will curl back in a whinny of excitement. You just know it.
So, um, my predecessor was self-taught, and by certain signifiers I can recognize elsewhere in the project, this code was written very early even by his standards.

Which is all the explanation or context I can offer for this, the greatest piece of bad code I've ever seen in my life. Please know that this in a specially created Person.cs file inside App_Code, and that this is the entirety of the file except for the includes, I'm not cherry-picking.

code:
namespace Company.People
{
    /// <summary>
    /// Represents a person in our system.
    /// </summary>
    public class Person
    {
        #region Constructors
        public Person()
        {
            
        }
        #endregion

        #region Private Properties
        private String fullName;
        #endregion

        #region Public Properties
        public String FullName
        {
            get { return this.fullName; }
            set { this.fullName = value; }
        }
        #endregion

        #region Private Methods
        #endregion

        #region Public Methods
        #endregion

        #region Static Methods
        #endregion
    }
}

Dross
Sep 26, 2006

Every night he puts his hot dogs in the trees so the pigeons can't get them.

You have to be a People.Person to work there.

but also

CapnAndy posted:

code:
        #region Private Properties
        private String fullName;
        #endregion

        #region Public Properties
        public String FullName
        {
            get { return this.fullName; }
            set { this.fullName = value; }
        }
        #endregion


I'm too new myself to feel confident saying this is as dumb as I think it is. It is, right?

Dross fucked around with this message at 00:52 on May 31, 2019

CapnAndy
Feb 27, 2004

Some teeth long for ripping, gleaming wet from black dog gums. So you keep your eyes closed at the end. You don't want to see such a mouth up close. before the bite, before its oblivion in the goring of your soft parts, the speckled lips will curl back in a whinny of excitement. You just know it.

Dross posted:

I'm too new myself to feel confident saying this is as dumb as I think it is. It is, right?
Declaring private variables just to get/set them with full permission public faces is extremely dumb, yes, although for the record they tried to drill that particular quirk into me in college because it's a best practice for some unfathomable reason -- I think just to get you used to the idea of getting and setting and that it can be done and to nudge you towards the idea that you can have whatever methods you like in there, or something. But yes, it's a waste of time.

Linear Zoetrope
Nov 28, 2011

A hero must cook

CapnAndy posted:

Declaring private variables just to get/set them with full permission public faces is extremely dumb, yes, although for the record they tried to drill that particular quirk into me in college because it's a best practice for some unfathomable reason -- I think just to get you used to the idea of getting and setting and that it can be done and to nudge you towards the idea that you can have whatever methods you like in there, or something. But yes, it's a waste of time.

I think the "idea" is future proofing in case you later discover you need to do some input validation or change a private cached field on input or something, so you can amend your Set method without affecting existing correct code.

This also is almost always foreseeable, or at least with experience you usually know when it might be the case in the future and can be defensive about it. Other than that? Just use a public field.

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.

Linear Zoetrope posted:

I think the "idea" is future proofing in case you later discover you need to do some input validation or change a private cached field on input or something, so you can amend your Set method without affecting existing correct code.
Yeah this is still common practice in traditional OOP circles, but in C# you can just use auto properties and get two birds with one stone.

Jazerus
May 24, 2011


CapnAndy posted:

Declaring private variables just to get/set them with full permission public faces is extremely dumb, yes, although for the record they tried to drill that particular quirk into me in college because it's a best practice for some unfathomable reason -- I think just to get you used to the idea of getting and setting and that it can be done and to nudge you towards the idea that you can have whatever methods you like in there, or something. But yes, it's a waste of time.

it's because java's getter/setter implementation brain damaged an entire generation by requiring explicit getButts/setButts calls, instead of making them a language feature for easily overloading access and assignment like in a sane language

Hammerite
Mar 9, 2007

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

CapnAndy posted:

So, um, my predecessor was self-taught, and by certain signifiers I can recognize elsewhere in the project, this code was written very early even by his standards.

Which is all the explanation or context I can offer for this, the greatest piece of bad code I've ever seen in my life. Please know that this in a specially created Person.cs file inside App_Code, and that this is the entirety of the file except for the includes, I'm not cherry-picking.

code:
namespace Company.People
{
    /// <summary>
    /// Represents a person in our system.
    /// </summary>
    public class Person
    {
        #region Constructors
        public Person()
        {
            
        }
        #endregion

        #region Private Properties
        private String fullName;
        #endregion

        #region Public Properties
        public String FullName
        {
            get { return this.fullName; }
            set { this.fullName = value; }
        }
        #endregion

        #region Private Methods
        #endregion

        #region Public Methods
        #endregion

        #region Static Methods
        #endregion
    }
}

It looks like it was automatically generated by some tool or other

Signed, some tool or other

dwazegek
Feb 11, 2005

WE CAN USE THIS :byodood:

Linear Zoetrope posted:

This also is almost always foreseeable, or at least with experience you usually know when it might be the case in the future and can be defensive about it. Other than that? Just use a public field.

In C# there's really no advantage to using public fields over properties, while there are a number of disadvantages*. You should always use public properties over fields, unless there is some explicit reason to use a field.

*Fields cannot be part of an interface, properties allow for different access modifiers on get/set, properties can be computed, changing a field is always a breaking API change, just to name a few.

NihilCredo
Jun 6, 2011

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

CapnAndy posted:

So, um, my predecessor was self-taught, and by certain signifiers I can recognize elsewhere in the project, this code was written very early even by his standards.

Which is all the explanation or context I can offer for this, the greatest piece of bad code I've ever seen in my life.

If is is 'the greatest piece of bad code you've ever seen' you've lived either a charmed or a short life.

Hammerite posted:

It looks like it was automatically generated by some tool or other

Signed, some tool or other

Not necessarily. My boss has the same pattern, because he simply starts every file by copy/pasting the #regions from a template file.

He actually goes much further, his classes are structured like this:

code:

#region "DECLARATIONS"

#region "FIELDS"
#endregion

#region "ENUMS"
#endregion

#region "STRUCTS"
#endregion

#endregion

#region "CONSTRUCTORS"
#endregion

#region "PROPERTIES"
#endregion

#region "METHODS"
#endregion

#region "EVENTS"
#endregion

#region "INTERNALS"
#endregion
It looks very nice in the autocollapse view, but 90% the time many of those regions are empty and 99% of the time you navigate files by symbol lookup anyway. :eng99:

And yes, I did show him how to use autoproperties but he still writes private fields and getters/setters :eng99:

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
If he wrote autoproperties, you wouldn't be able to see all the fields just by expanding the FIELDS section!

What's an outliner?

Adbot
ADBOT LOVES YOU

Munkeymon
Aug 14, 2003

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



Linear Zoetrope posted:

I think the "idea" is future proofing in case you later discover you need to do some input validation or change a private cached field on input or something, so you can amend your Set method without affecting existing correct code.

It's 100% because you used to have to write out all that crap by hand back in the dark ages of language version < 3 and someone internalized the only way as the only right way when the world moved on.

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