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
shrughes
Oct 11, 2008

(call/cc call/cc)

JawnV6 posted:

I can think you're an incorrect jackass without signing up to defend code I didn't write in a language I don't use.

You've been calling a lot of people names lately.

Adbot
ADBOT LOVES YOU

ultramiraculous
Nov 12, 2003

"No..."
Grimey Drawer

Deus Rex posted:

Is Postgres the only SQL DB that can do indexes on expressions? I wasn't that surprised to see MySQL was lacking them, but SQL Server is supposed to be good :(

I know you can do filtered indexes on SQL Server, which would at least speed up groupings based on time periods (like the aforementioned fiscal years, etc). I'm not much of a SQL wizard, though, so there might be other options as well.

shrughes posted:

You've been calling a lot of people names lately.

Take the meds, shrughes.

gonadic io
Feb 16, 2011

>>=

Athas posted:

<ghc tuple horror>

So one fix to this could be to give tuples a sugar, much like as is done for lists currently, so that n-tuples are actually n nested 2-tuples (i.e. a heterogeneous list) . This would lead to something like the following code:
code:
type (,,) a b c = (a, (b, c)) -- normal type definition
pattern (a,b,c) = (a, (b, c))  -- PatternSynonyms
instance (Eq a, Eq b) => Eq (a, b) where ...

secondOfThree :: (a,b,c) -> b
secondOfThree (_, b, _) = b
While the type and pattern definition will still need to be recreated for each tuple length, you save the boilerplate for all the other instances. What do you think?

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed

Deus Rex posted:

Is Postgres the only SQL DB that can do indexes on expressions? I wasn't that surprised to see MySQL was lacking them, but SQL Server is supposed to be good :(
You can't index the expression directly, but you can create a view with that expression and then put an index on that.

Zombywuf
Mar 29, 2008

AlsoD posted:

So one fix to this could be to give tuples a sugar, much like as is done for lists currently, so that n-tuples are actually n nested 2-tuples (i.e. a heterogeneous list) . This would lead to something like the following code:
code:
type (,,) a b c = (a, (b, c)) -- normal type definition
pattern (a,b,c) = (a, (b, c))  -- PatternSynonyms
instance (Eq a, Eq b) => Eq (a, b) where ...

secondOfThree :: (a,b,c) -> b
secondOfThree (_, b, _) = b
While the type and pattern definition will still need to be recreated for each tuple length, you save the boilerplate for all the other instances. What do you think?

Or just do it the c++ way with something like (x, ...xs) and recurse on xs.

Athas
Aug 6, 2007

fuck that joker

AlsoD posted:

While the type and pattern definition will still need to be recreated for each tuple length, you save the boilerplate for all the other instances. What do you think?

Apart from the fact that you will no longer be able to distinguish (a,(b,c)) from (a,b,c), this is not a bad idea. I've had similar thoughts before.

Jethro
Jun 1, 2000

I was raised on the dairy, Bitch!

Deus Rex posted:

Is Postgres the only SQL DB that can do indexes on expressions? I wasn't that surprised to see MySQL was lacking them, but SQL Server is supposed to be good :(
Oracle has Function-Based Indexes

The closest equivalent in SQL Sever is to create a computed column on the table and index that.

Plorkyeran posted:

You can't index the expression directly, but you can create a view with that expression and then put an index on that.
Indexed views in SQL Server are equivalent to materialized views in Oracle or Postgres, so there's a bit more to it than just slapping an index on any old view.

1337JiveTurkey
Feb 17, 2005

Subjunctive posted:

I'm sorry if you thought I was impugning you, rather than your argument. Code with a lot of non-caller-controlled dependencies is IME (very large systems, but in a bunch of domains) fragile and hiding it doesn't help things. PFA can be ugly, though mostly in OO situations you isolate that to initialization. DI systems are, I find, much harder to reason about than ones built around fully-parametrized components that you can test piecewise and incrementally, and I'm surprised that in an embedded context the time and space overhead isn't problematic for you! I've worked in DI environments (the apps I most recently managed at work are built around it, and they do OK), I just find it to be like the general OO action-at-a-distance ick. "Oh, you called this method and it didn't work? Did you call this other invisibly-related one first? Does it have leftover state from a previous thing?"

IME if you have the caller responsible for all dependencies, then interface polymorphism is impossible without every possible dependency of every possible implementation of a particular interface passed through it. In practice this means that either the interface ends up with the parameters needed by existing implementation or that interfaces get some sort of God Object parameter that they can use to do everything anyhow. Changing the dependencies of a function or method used widely throughout the system with interfaces tightly tied to implementations breaks huge swathes of code that were nominally coding to the interface since they've suddenly gained new transitive dependencies that their callers have to provide.

Besides, there's plenty of shared mutable global resources that people use all the time without passing them as parameters. Anything managed by the operating system in general is likely going to be shared, like log files, network sockets, synchronization primitives or just memory in general. The caller isn't providing the space for the next invocation record, nor is it providing the heap. Expecting the caller to actually provide those would be completely insane but that doesn't make them any less global. Spooky action at a distance can still cause them to fail (stack overflow) and there are systems that don't have those resources and simply allocate everything statically at compile time so no recursion is allowed. The reason those resources work is because they're managed through a shared protocol, something which DI contexts give a solid foundation for over "less complicated" ad hoc implementations.

Sedro
Dec 31, 2008

Deus Rex posted:

Is Postgres the only SQL DB that can do indexes on expressions? I wasn't that surprised to see MySQL was lacking them, but SQL Server is supposed to be good :(
Newer versions of DB2 can do this also. However like all databases other than Postgres, you can't mix features, e.g. you can't index on an expression which calls a UDF.

omeg
Sep 3, 2012

Today I embarked on a quest to understand why my Menu Start-parsing script failed to retrieve .exe paths for MS Office programs. Turned out the rabbit hole is pretty deep.

code:
$WshShell = new-object -comobject "WScript.Shell"
$link = $WshShell.CreateShortcut($pathObj.FullName)
Write-Host "$($link.TargetPath)"
This works for most shortcuts but some fail, like Office apps. Example result:

pre:
C:\Windows\Installer\{90120000-0030-0000-0000-0000000FF1CE}\wordicon.exe
Isn't it strange? This exe is resource-only and contains no code. After some googling I found this:

quote:

The HasDarwinID flag is enabled which means the shortcut contains a DarwinDataBlock:

The DarwinDataBlock structure specifies an application identifier that can be used instead of a link targetIDList to install an application when a shell link is activated.

In this case the application identifier is Q9UW!o_!_?09WJ'i$c!+>Ipj.(bOirX&j$Vp+8v_j, which can be found in the HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Installer\Assemblies\C:|Program Files (x86)|Zqueue|ServeToMe|ServeToMe.exe registry key.

This cryptic-looking string, sometimes referred to as a "Darwin Descriptor," is actually an encoded representation of a specific product, component, and feature. If this extra value exists, Windows Installer will decode the data, and use it to perform checks against that product and component. If the component is found to be missing or corrupt, Windows Installer will launch a repair to restore the missing file or data, and finally launch the referenced application as normal, passing the appropriate command-line options to it.

:stare:
Well, how to decode this then? After some more searching I found this:

quote:

The string starting with 26,... is a component identifier. The first and 20 characters are a GUID encoded in base 85, and the middle portion, up to the > character is the feature identifier. For Windows versions below Vista you can include both the product id and the component id, but Vista and higher don't accept a path that contains the product id tag/guid. All versions accept a path consisting of just the component id tag and component id.

:stonk:
Okay... Base85? No problem! Only all my attempts to decode it failed to produce any usable GUID. More searching! Oh, it seems MS is using its own, non-standard implementation! So now I can retrieve the exe path in just few easy steps:
  • Retrieve the DarwinID from the shortcut
  • Convert 20 characters after '>' using the above Base85 algorithm into a packed GUID (NOT the normal hyphenated form)
  • Open registry key at HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Components\packed_guid (S-1-5-18 is LocalSystem SID)
  • Read a value with name equal to Office's ProductID converted to a packed GUID
  • You have the executable path!

Who comes up with this stuff? :shepicide:

astr0man
Feb 21, 2007

hollyeo deuroga
How does source control work :downs:

C++ code:
// BUG ########1 FIX THIS BY REMOVING IF STATEMENT
// BUG ########4 REVERT ABOVE CHANGE BECAUSE IT BROKE SOMETHING PUT IF STATEMENT BACK
*if statement still doesnt exist*
Note that the nonexistent if statement is correct, but the comments are like 5 years old and whoever finally fixed the issue just didn't bother deleting all the old comments :cripes:

Powerful Two-Hander
Mar 10, 2004

Mods please change my name to "Tooter Skeleton" TIA.


I finally got access to one of our repos that another team has been working on, specifically adding a webservice to access functions in an existing application. Pretty straightforward stuff right? Heh.

code:
string xml = [inbound xml from the webservice];

xDocument document = ParseXML(xml);

Public static class ParseXML(string xml)
{

parsedxml= [regex what the actual gently caress](xml);

return parsedxml;

}

This is only the beginning. Want to get node content? Why would you use standard functions when you could write your own? Why is the XML loaded as a string anyway? And why is this an asmx service when it's .net 3.5 and it could be WCF so you could actually have proper security? Why is the xml being "parsed" then every single node hand coded to convert to the object classes instead of using a custom class for the message content and loading straight into that?

It is like an experiment in finding the optimum worst way to implement an xml based web service.

Scaevolus
Apr 16, 2007

AlsoD posted:

So one fix to this could be to give tuples a sugar, much like as is done for lists currently, so that n-tuples are actually n nested 2-tuples (i.e. a heterogeneous list).

Having recursive heterogeneous lists is nontrivial.

Duplicating some code 15 times is annoying, but that's far simpler than 5 type system extensions to express nested 2-tuples. And if you have tuples more than 15 long, your program is probably a complete mess anyways.

gonadic io
Feb 16, 2011

>>=

Scaevolus posted:

Having recursive heterogeneous lists is nontrivial.

Duplicating some code 15 times is annoying, but that's far simpler than 5 type system extensions to express nested 2-tuples. And if you have tuples more than 15 long, your program is probably a complete mess anyways.

I see, well I take back what I said. The longest tuple I've ever used was a 4-tuple because I wanted to use unboxed vectors of my type (vectors of tuples get converted to tuples of vectors) and didn't want to add such an instance myself. Even then it was cumbersome to use and I ended up having to use newtypes for all 4 different components (which were Ints at heart) because I kept getting them mixed up.

pseudorandom name
May 6, 2007

omeg posted:

Today I embarked on a quest to understand why my Menu Start-parsing script failed to retrieve .exe paths for MS Office programs. Turned out the rabbit hole is pretty deep.

The horror here is that you're reinventing MsiGetShorcutTarget() and MsiGetComponentPath(), although I have no idea how you'd get at this functionality from PowerShell.

omeg
Sep 3, 2012

pseudorandom name posted:

The horror here is that you're reinventing MsiGetShorcutTarget() and MsiGetComponentPath(), although I have no idea how you'd get at this functionality from PowerShell.

Now I feel stupid. I've looked through the Msi* functions but I missed the one that gets info from a shortcut. Still, the implementation is :eng99:

Amberskin
Dec 22, 2013

We come in peace! Legit!
For old-schoolers only (this is PL/I code!):

code:
/*==================================================================*/
/*  TRANSFORM BIN FIXED INTO CHAR                                   */
/*==================================================================*/
  TRANS_BIN: PROC(BFIXED_E) RETURNS(CHAR(10));                        
                                                                       
    DCL BFIXED_E   BIN FIXED(31);                                     
    DCL PICDE10    PIC'(10)9'       INIT(0);                          
    DCL CHARDE10   CHAR(10)         BASED(ADDR(PICDE10));             
    DCL COUNTER    FIXED(9)         INIT(0);                          
                                                                       
    DO COUNTER = 1 TO BFIXED_E;                                      
    END;                                                               
    PICDE10 = COUNTER - 1;                                           
    RETURN(CHARDE10);                                                 
                                                                       
  END TRANS_BIN;                                                      
This code was flagged as high CPU consumer. The guy who does the code audit almost fell from his chair.

Amberskin fucked around with this message at 11:41 on Apr 3, 2014

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
I would love an explanation, if you've got the time and patience.

Amberskin
Dec 22, 2013

We come in peace! Legit!

pokeyman posted:

I would love an explanation, if you've got the time and patience.

That abomination tries to convert a BINARY FIXED(31), which is simply a 32 bit signed integer, to its CHAR (string) representation. PL/I can do it as easily as assigning the integer value into a "picture string' value (the field PICDE10 in that code). But this guy didn't do that. He wrote a loving loop to increment a third variable (a decimal one, COUNTER) by one for each value between 1 and the value to convert. Then he substracts one, because the loop limit is not correct and assigns the decimal to the picture variable. So a simple assignement, which in the mainframe compiles to ONE loving MACHINE INSTRUCTION is implemented using a loop incrementing a decimal counter.

Its like if to convert an long to a float in C you code this:

code:
float int2float(int value) {
    float thecounter = 0.;

    for (i=1; i++; i<= value) {
        thecounter++:
    }
    thecounter--;
    return(thecounter);
}
It works, but of course if the value to convert is in the thousand of billions it sucks a little bit excessive CPU time.

Oh, did I tell you IBM charges $$$ according to your CPU usage?

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
That's absolutely wonderful. Thanks for writing it out.

PrBacterio
Jul 19, 2000

pokeyman posted:

That's absolutely wonderful. Thanks for writing it out.
Is it odd that I don't find the fact that people can't even read PL/I, and therefore needed a translation, wonderful at all? It makes me feel even older than I actually am ... :(

substitute
Aug 30, 2003

you for my mum
Not code, but "documentation".

Click to enlarge and read.



(CakePHP... when you unzip it.)

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

PrBacterio posted:

Is it odd that I don't find the fact that people can't even read PL/I, and therefore needed a translation, wonderful at all? It makes me feel even older than I actually am ... :(

I wouldn't take it as an age thing, I just hadn't before experienced the joy of trying to read some PL/I. Now I've torn down that wall and am a better person because of it.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug
One of my least-sophisticated clients emailed me to complain today:

Client: The CI build you set up for us for our SQL database projects passed, but it failed when we deployed because of a bad database reference. Why didn't the build fail for this?
Me: Well, the default behavior is to emit a warning for that, not an error, because you might be referring to a column in another database that's not a part of your solution.
Client: That should be an error!
Me: We can turn on "treat warnings as errors" if you want, but you currently have over 5000 warnings when building.
Client: Nevermind.

All of their stuff throws thousands of warnings when building. They love warnings. They even had me turn on static analysis so they can get even more warnings. They currently get over 10,000 warnings on every build of their application, plus dozens of totally ignored test failures. Of course, their tests are lovely and useless anyway, so it balances out.

ManoliIsFat
Oct 4, 2002

10,000 warnings about what?! Unused variables? Unreachable code? That's insanity!

ultramiraculous
Nov 12, 2003

"No..."
Grimey Drawer

Amberskin posted:

Oh, did I tell you IBM charges $$$ according to your CPU usage?

Oh, nice! It's almost like you paid for this guy's work twice!

New-ShitPost
Jul 25, 2011

code:
            DeviceTypeId vDevType = PDConfig.DeviceType;
            PDConfig.DeviceType = vDevType;
what

HFX
Nov 29, 2004

ManoliIsFat posted:

10,000 warnings about what?! Unused variables? Unreachable code? That's insanity!

I find very few developers pay attention to warnings. It drives me nuts.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

ManoliIsFat posted:

10,000 warnings about what?! Unused variables? Unreachable code? That's insanity!

Yes, both of those. Also every Code Analysis / FXCop violation. Some are minor, some are major, but they want to be warned about everything even though they have no intention of actually changing any of it.

Azerban
Oct 28, 2003



HFX posted:

I find very few developers pay attention to warnings. It drives me nuts.

I've gotten the project I took over down from 800+ to 4 over the last few months. Imagine the day, when a warning is actually a warning!

Amberskin
Dec 22, 2013

We come in peace! Legit!

pokeyman posted:

I wouldn't take it as an age thing, I just hadn't before experienced the joy of trying to read some PL/I. Now I've torn down that wall and am a better person because of it.

Well, you just read horrible PL/I code :) The MULTICS source code contains a lot of well written PL/I

http://web.mit.edu/multics-history/

Dessert Rose
May 17, 2004

awoken in control of a lucid deep dream...

HFX posted:

I find very few developers pay attention to warnings. It drives me nuts.

A somewhat-new coworker took it upon himself to fix every last warning (we had about 200) and then campaigned to have warnings as errors turned on.

He succeeded, but I swear it's bitten us in our asses more than anyone else. Still, it's really nice to see a totally green build mail every morning.

b0lt
Apr 29, 2005

Dessert Rose posted:

A somewhat-new coworker took it upon himself to fix every last warning (we had about 200) and then campaigned to have warnings as errors turned on.

He succeeded, but I swear it's bitten us in our asses more than anyone else. Still, it's really nice to see a totally green build mail every morning.

the horror is coming from inside the house

No Safe Word
Feb 26, 2005

ManoliIsFat posted:

10,000 warnings about what?! Unused variables? Unreachable code? That's insanity!

If you use the strictest Code Analysis settings, it can be pretty anal about a lot of stuff. We've turned it up fairly high and I've had to scatter a fair amount of suppression. "Yes I know that variable is named FooUri but is of type string and yes it's okay"

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe

Dessert Rose posted:

A somewhat-new coworker took it upon himself to fix every last warning (we had about 200) and then campaigned to have warnings as errors turned on.

He succeeded, but I swear it's bitten us in our asses more than anyone else. Still, it's really nice to see a totally green build mail every morning.

Why did it bite you in your rear end?

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
Turning incorrect and misleading code that works by coincidence into code that doesn't work at all while trying to fix warnings is pretty common. It's nearly always worth it in the long run, but fixing hundreds of warnings is very likely to cause some short-term pain.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Plorkyeran posted:

fixing hundreds of warnings is very likely to cause some short-term pain.

Very true, especially if you're doing weird poo poo at runtime with reflection.

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

johnduhart posted:

code:
            DeviceTypeId vDevType = PDConfig.DeviceType;
            PDConfig.DeviceType = vDevType;
what

Sometimes that's coping with a horror, where resetting a value causes the system underneath to reprocess something (I think a goon wrote up a description of SpriteKit gems including that one). In that case it should include an exasperated comment at the least, so horror indeed.

img-timeline but:

1337JiveTurkey posted:

IME if you have the caller responsible for all dependencies, then interface polymorphism is impossible without every possible dependency of every possible implementation of a particular interface passed through it. In practice this means that either the interface ends up with the parameters needed by existing implementation or that interfaces get some sort of God Object parameter that they can use to do everything anyhow.

Yeah, you're right about widely-implemented interfaces, especially where the construction of the implementation isn't relatively centralized. (In an OO environment I don't consider construction parameters to be action at a distance, since it's inherent in any use of an object. Some don't consider any member field to be a-a-a-d, and I can see that position.) That's a case where PFA doesn't work as well by a long shot. It's pretty common in our code base to see DI at the module level, and then PFA where possible to dependencies or inner objects.

You're right that PFA can result in ugliness in some cases that exceeds that of DI's boilerplate or whatever. It probably doesn't help that most of the DI-heavy systems I've worked with are C++ and Android-Java, where the cognitive or runtime overhead can be pretty unpleasant. (In the latter case we wrote a transformation pass to replace the DI hooks with direct allocation for space+time performance reasons.)

Thanks, that was a helpful thing to point out.

Internet Janitor
May 17, 2008

"That isn't the appropriate trash receptacle."
At one of my old jobs I had turned in my two week notice and my boss said I should stay around for the whole time in case anybody had questions about the stuff I was maintaining. I wasn't getting assigned any new tasks, so to stave off boredom I started poking around in test fixtures and found that we had about 600 end-to-end tests that were failing. The product was basically an API for reading and writing Word and Excel files, and those tests were all based around manipulating a stable of several thousand random documents found on the internet, opening them, reading data, saving them back out and verifying integrity. Over the course of my remaining days I tracked down about a dozen bugs that accounted for all those failing tests. It was incredibly gratifying to walk away from that codebase with every test fixture lit up green. Practice random acts of kindness to your codebases when you have the chance. It can take a long time to deal with thousands of warnings or failing tests but you can make it through to the other side.

Adbot
ADBOT LOVES YOU

ultramiraculous
Nov 12, 2003

"No..."
Grimey Drawer

Subjunctive posted:

Sometimes that's coping with a horror, where resetting a value causes the system underneath to reprocess something (I think a goon wrote up a description of SpriteKit gems including that one). In that case it should include an exasperated comment at the least, so horror indeed.

This is what I would have figured. The SpriteKit guy was talking about how he had to set some other value like .alpha to a slightly different value every time he wanted some other change to commit, because whatever he was trying to do wasn't properly triggering a redraw and there wasn't a public method to initiate a redraw. I could imagine the setter method for "PDConfig.DeviceType = vDevType" causes some side effects that may/may not be exposed elsewhere. Not having a comment explaining this behavior isn't great, though.

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