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
Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
Today I'm writing a WCF web service to wrap an excel spreadsheet so that the team responsible for the sheet can update the calculations done on the production server without going through the dev team or any sort of change control.

Adbot
ADBOT LOVES YOU

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

Ensign Expendable posted:

I saw this in production code before. Sadly, I fixed it and I can't be bothered to dig through subversion, but it was very similar. A dozen or so constructs, with hardcoded (identical) UI elements for each, a few boolean flags, three ArrayLists, some Strings. And lots and lots of if statements. When I rewrote the class to use a HashMap and proper OOP, I think it ended up being about a tenth of its original size.

I had to do something similar as well; it was because the guy who created the original table denormalized it into setting / value pairs. The table looked like this:
code:
Name | Setting | Value
Site1| URL     | [url]http://www.thing.com[/url]
Site1| Logo    | Logo.png

etc., about 15 times for each 'Name'
The problem was the guy who wrote the parser, who decided that all of these have to be in order or else it breaks/applies random values to random settings. But there's no way to order them. So I had to make 15 interface elements numbered 1-15 and use that as an informal index. Didn't get fixed until a year later when we got sick of it and made the first guy put a synthetic PK on the table.

Profane Obituary!
May 19, 2009

This Motherfucker is Dead

Scaramouche posted:

I had to do something similar as well; it was because the guy who created the original table denormalized it into setting / value pairs. The table looked like this:
code:
Name | Setting | Value
Site1| URL     | [url]http://www.thing.com[/url]
Site1| Logo    | Logo.png

etc., about 15 times for each 'Name'
The problem was the guy who wrote the parser, who decided that all of these have to be in order or else it breaks/applies random values to random settings. But there's no way to order them. So I had to make 15 interface elements numbered 1-15 and use that as an informal index. Didn't get fixed until a year later when we got sick of it and made the first guy put a synthetic PK on the table.

wait, how did this even work?? Surely to get the value of a setting it was just doing:
code:
SELECT Value FROM "table" WHERE "Name" = "Site1" AND "Setting" = "Logo";
... right? please?

baquerd
Jul 2, 2007

by FactsAreUseless

Profane Obituary! posted:

wait, how did this even work?? Surely to get the value of a setting it was just doing:
code:
SELECT Value FROM "table" WHERE "Name" = "Site1" AND "Setting" = "Logo";
... right? please?

I bet it goes like this:

code:
resultSet = doSql(select * from table where Name = "Site1");

URL = resultSet.getString(2);
resultSet.next();
Logo = resultSet.getString(2);
//....

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

^^^ Exactly. It was an enormous pain in the rear end, especially because in that year before we fixed it they'd be adding totally new 'Setting's, and I'd have to renumber the goddamn interface/update method. There's 38 settings now.

The real sad thing I guess, is that when I did my half all I did was make a central array of settings, and then create controls/write updates based on going For...Next through that array. So I'd have say 30 lines on instantiation, but only 3 lines per operation (For, <something>, Next). I showed it to the first guy who had hundreds of hardcoded statements (e.g. the Dims, the assignments, etc.) and he just said 'oh' and looked kind of sad.

ultramiraculous
Nov 12, 2003

"No..."
Grimey Drawer

baquerd posted:

I bet it goes like this:

Oh Jesus, you're probably right.

Goat Bastard
Oct 20, 2004

I wish I had a dollar for every time I've had to explain to a senior developer that the order of a result set is undefined unless the query has an ORDER BY clause

NotShadowStar
Sep 20, 2000
But they go into the table in a certain order!

blorpy
Jan 5, 2005

here's a cool thing, it's the run loop for erlang
https://github.com/erlang/otp/blob/dev/erts/emulator/beam/beam_emu.c

im not going to quote it because it's 6500 lines and i don't feel like i could do it justice, but just click and have a look

tef
May 30, 2004

-> some l-system crap ->
it has a bunch of op codes and a dispatch mechanism :confused:

vm code is never going to win beauty contests

Goat Bastard
Oct 20, 2004

NotShadowStar posted:

But they go into the table in a certain order!

But tables have primary keys! Surely THAT'S the default order!

Goat Bastard fucked around with this message at 08:20 on Aug 19, 2011

blorpy
Jan 5, 2005

tef posted:

it has a bunch of op codes and a dispatch mechanism :confused:

vm code is never going to win beauty contests

fair enough, you're right. it's not a horror, but i don't envy the people who have to maintain it

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope
Boss (on Tuesday): This [silly quiz program] needs to have these features by next Tuesday, do you think you can do it? And don't worry about it, if it's not done, we'll just use pen and paper for the quiz.

Me: I haven't really coded that much (or at all, really) with C#, but yeah, probably.

By Friday around noonish, the program has pretty much all the features requested (but is in need of some testing). And it has some silly animations, like the currently active contestants names flocking around a "black hole" on the right side of the screen.

Boss, Friday, 2 pm: Oh, can you make the screen bigger, currently only the top 17 contestants on the ranking list fit on the screen.

Me: Well, sure ( I guess I'll change some of those text positions to be relative to the screen-size like I originally planned :geno: )

Boss, Friday, 4 pm: Now can you make the font for the contestants bigger. Also, could you make the font scale with the number of contestants or the list scroll or make the ranking list two columns so that all ~30 contestants can fit on screen. Oh, and if a client drops or cancels, their name is left on screen flocking. And could you make the server save its state in case it crashes or needs a restart.

Me: :what: Okay yes, I can change the font, but not very often. I've used hardcoded offsets so that the text doesn't overlap, because this was supposed to be a silly toy program, so changing the font requires me to change the value of a bunch of constants.

That other stuff can be done, but gently caress, I could have used these requirements like 3 days ago, not at 4 pm on Friday :suicide:

I guess this overlaps with the poo poo that pisses me off thread.

1337JiveTurkey
Feb 17, 2005

Goat Bastard posted:

I wish I had a dollar for every time I've had to explain to a senior developer that the order of a result set is undefined unless the query has an ORDER BY clause

Varrays and pipelined functions called through the table operator without any subsequent joins in Oracle should be in order. At least I hope they are since I just ended up writing a query which relies on that to avoid generating a crapload of extra data just so I could sort it. :ohdear:

Goat Bastard
Oct 20, 2004

1337JiveTurkey posted:

Varrays and pipelined functions called through the table operator without any subsequent joins in Oracle should be in order. At least I hope they are since I just ended up writing a query which relies on that to avoid generating a crapload of extra data just so I could sort it. :ohdear:

Sure, as long as you ordered the rows inside the function. That's sort of a special case though.

plushpuffin
Jan 10, 2003

Fratercula arctica

Nap Ghost

Goat Bastard posted:

I wish I had a dollar for every time I've had to explain to a senior developer that the order of a result set is undefined unless the query has an ORDER BY clause

My organization is currently switching over from the Paradox database to Oracle, which means that there are thousands of SQL queries throughout our massive legacy program that need to have columns and tables renamed/escaped (different reserved words) and order by clauses added (Paradox orders the data in tables by primary key(s), and queries and cursors always return data ordered by the primary keys). We had some terrible developers in the past who were really lazy, and Paradox encouraged some bad habits.

I managed to put a huge band-aid over the problem by writing a SQL parser to auto-correct/escape the column names in queries (a little difficult since I had to actually parse the query to avoid escaping legitimate uses of reserved words). I also wrote a function to query the Oracle database for its primary keys and cache them, then append them to queries against single tables that don't have an order by (as determined by the parser). :v:

Opinion Haver
Apr 9, 2007

Found another Dive into Python horror: in its example of file IO, it uses magic numbers instead of telling you 'hey the os module has some relevant constants you should use':

quote:

The seek method of a file object moves to another position in the open file. The second parameter specifies what the first one means; 0 means move to an absolute position (counting from the start of the file), 1 means move to a relative position (counting from the current position), and 2 means move to a position relative to the end of the file. Since the MP3 tags you're looking for are stored at the end of the file, you use 2 and tell the file object to move to a position 128 bytes from the end of the file.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
See this is why typed enumerations are a good thing.

xf86enodev
Mar 27, 2010

dis catte!

yaoi prophet posted:

Found another Dive into Python horror: in its example of file IO, it uses magic numbers instead of telling you 'hey the os module has some relevant constants you should use':

The official library reference suggests the use of constants or magic numbers is correct, so I guess Mark just wanted to save bandwidth.

xf86enodev fucked around with this message at 08:39 on Aug 22, 2011

pseudorandom name
May 6, 2007

The Unix lseek() function originally didn't have the SEEK_SET/SEEK_CUR/SEEK_END macros for the whence parameter and you were expected to pass 0/1/2 directly.

There is no excuse for that stupidity to be propagated to Python, though.

LOOK I AM A TURTLE
May 22, 2003

"I'm actually a tortoise."
Grimey Drawer

xf86enodev posted:

The official library reference suggests the use of constants or magic numbers is correct, so I guess Mark just wanted to save bandwidth.

He was probably referring to the use of 2 instead of os.SEEK_END. The python.org example only uses a magic number for the number of bytes to read, not for the seek mode. The number 128 in the Dive Into Python example is also something that could be put in a constant like MP3_TAG_SIZE or whatever, but that isn't a constant you can expect Python itself to know about.

Malloc Voidstar
May 7, 2007

Fuck the cowboys. Unf. Fuck em hard.
code:
$ php -r 'var_dump("99999999999999991111111111111111" == "99999999999999990000000000000000");'
bool(true)
These strings look like numbers, let's compare them as numbers!

tef
May 30, 2004

-> some l-system crap ->
php -r 'var_dump("\n\n0099999999999999991111111111111111" == " 99999999999999990000000000000000");'

recall when strings are treated like numbers, any leading whitespace or 0 is truncated :eng101:

Malloc Voidstar
May 7, 2007

Fuck the cowboys. Unf. Fuck em hard.
https://bugs.php.net/bug.php?id=55439

quote:

Bug #55439 crypt() returns only the salt for MD5

Test script:
---------------
printf("MD5: %s\n", crypt('password', '$1$U7AjYB.O$'));

Expected result:
----------------
MD5: $1$U7AjYB.O$L1N7ux7twaMIMw0En8UUR1

Actual result:
--------------
MD5: $1$U7AjYB.O
They don't even test their crypto code?

quote:

[2011-08-19 22:19 UTC] stas@php.net

Confirming, some very recent update broke it - right now unit tests fail on SVN. I wonder if nobody run it before release?
...oh

NotShadowStar
Sep 20, 2000
I'd call that a feature. Leave it in to get people to stop using MD5.

zombienietzsche
Dec 9, 2003
code:
textValue = row.Elements<DocumentFormat.OpenXml.Wordprocessing.TableCell>().First().Elements<DocumentFormat.OpenXml.Wordprocessing.Paragraph>().First().Elements<DocumentFormat.OpenXml.Wordprocessing.Run>().First().Elements<DocumentFormat.OpenXml.Wordprocessing.Text>().First().Text;
WHY DEAR GOD WHY

Smugdog Millionaire
Sep 14, 2002

8) Blame Icefrog
I write code like that all the time. It owns.

Hughlander
May 11, 2005

meinstein posted:

code:
textValue = row.Elements<DocumentFormat.OpenXml.Wordprocessing.TableCell>().First().Elements<DocumentFormat.OpenXml.Wordprocessing.Paragraph>().First().Elements<DocumentFormat.OpenXml.Wordprocessing.Run>().First().Elements<DocumentFormat.OpenXml.Wordprocessing.Text>().First().Text;
WHY DEAR GOD WHY

As someone who just read the Law of Demeter paper this weekend, I think to myself, "Ohhh this is the poo poo they're talking about."

Milotic
Mar 4, 2009

9CL apologist
Slippery Tilde
It's not really that much of a horror. Needs a comment describing what it does / the expected format of the Word document, and probably some better error handling / checking for nulls, but that looks like fairly standard Linq to XML.

The Open XML SDK was always a bit horrible. It's enough to make you miss PIAs sometimes.

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

meinstein posted:

code:
textValue = row.Elements<DocumentFormat.OpenXml.Wordprocessing.TableCell>().First().Elements<DocumentFormat.OpenXml.Wordprocessing.Paragraph>().First().Elements<DocumentFormat.OpenXml.Wordprocessing.Run>().First().Elements<DocumentFormat.OpenXml.Wordprocessing.Text>().First().Text;
WHY DEAR GOD WHY

Couldn't you use an xpath?
code:
textValue = row.down('descendant-or-self::tablecell/descendant::paragraph/descendant::run/descendant::text').first.text

Sedro
Dec 31, 2008
It's doesn't look so bad if you add some whitespace
code:
import DocumentFormat.OpenXml.Wordprocessing
...
textValue = row
    .Elements<TableCell>()
    .First()
    .Elements<Paragraph>()
    .First()
    .Elements<Run>()
    .First()
    .Elements<Text>()
    .First()
    .Text;
Then maybe create a utility method to reduce code duplication
code:
textValue = row
    .First<TableCell>()
    .First<Paragraph>()
    .First<Run>()
    .First<Text>()
    .Text;

Milotic
Mar 4, 2009

9CL apologist
Slippery Tilde

BonzoESC posted:

Couldn't you use an xpath?
code:
textValue = row.down('descendant-or-self::tablecell/descendant::paragraph/descendant::run/descendant::text').first.text

In my opinion, XPath/pre-Linq-to-Xml processing isn't great in .NET. It's painful having to mess around with Xml namespaces and the libraries and concepts aren't very intuitive. Additionally, the Office Open XML format is quite verbose and complex and does some surprising things that can make XPath a bad choice. The documents are composed of several zipped folders, Xml files and binary resources.

Case in point, Excel supports drag-and-filling of a formula into adjacent cells, with relative cells changing as the columns and rows change. However in the Xml, the adjacent cells are stored with a reference the formula in the master cell, with interpolation of the actual formula being done at runtime. I had to parse the bloody things once, that sure was fun!

So yeah, Linq to Xml coupled with the OpenXML SDK is actually the sanest solution here, apart from possibly using the PIAs if performance isn't a problem and you don't mind all the 'joys' that come from running Word in headless mode.

Zombywuf
Mar 29, 2008

tef posted:

it has a bunch of op codes and a dispatch mechanism :confused:

vm code is never going to win beauty contests

Yeah, but they're pretending to write a compiler. If they wanted to do that they should have done so. As it stands, that is horrific code.

Meliv
Nov 1, 2008
Just came across this gem while looking for stuff online


code:
// set price range
        if ($price < 1) {
                $price = '["price=0 to 500000000000"]';
        } elseif ($price == 1) {
                                $price = '["price=0 to 50000"]';
                } elseif ($price == 2) {
                                        $price = '["price=50000 to 100000"]';
                        } elseif ($price == 3) {
                                                $price = '["price=100000 to 150000"]';
                                } elseif ($price == 4) {
                                                        $price = '["price=150000 to 200000"]';
                                        } elseif ($price == 5) {
                                                                $price = '["price=200000 to 250000"]';
                                                } elseif ($price == 6) {
                                                                        $price = '["price=250000 to 350000"]';
                                                                } elseif ($price == 7) {
                                                                                $price = '["price=350000 to 400000"]';
                                                                        } elseif ($price == 8) {
                                                                                        $price = '["price=400000 to 500000"]';
                                                                                } elseif ($price == 9) {
                                                                                                $price = '';
                                                                                        }
        // set property type range
        if ($property_type < 0) {
                $prop_type = '';
        } elseif ($property_type == 1) {
                        $prop_type = '[type/en="Apartment"]';
                } elseif  ($property_type == 2) {
                                        $prop_type = '[type/en="Duplex"]';
                                } elseif ($property_type == 3) {
                                                $prop_type = '[type/en="Town house"]';
                                                } elseif ($property_type == 4) {
                                                        $prop_type = '[type/en="Villa"]';
                                                        } elseif  ($property_type == 5) {
                                                                $prop_type = '[type/en="Cortijo"]';
                                                                } elseif ($property_type == 6) {
                                                                        $prop_type = '[type/en="Log home"]';
                                                                        } elseif ($property_type == 7) {
                                                                                $prop_type = '[type/en="Finca"]';
                                                                                } elseif ($property_type == 8) {
                                                                                        $prop_type = '[type/en="Bungalow"]';
                                                                                        } elseif ($property_type == 9) {
                                                                                                $prop_type = '[type/en="Pentouse"]';
                                                                                                } elseif ($property_type == 10) {
                                                                                                        $prop_type = '[type/en="Cave house"]';
                                                                                                        }
        // set berrom no range                                                                                          
        //if ($bedroom_no > 4){
//              $bedroom_no = "[beds>4]";       
        if ($bedroom_no < 1){ 
                $bedroom_no = "[beds>0]";
        } else {
                $bedroom_no = "[beds=$bedroom_no]";
        }                                                                               
        
                                                
                                                                
                 // Include the pagination class
                include 'pagination.class.php';
                // Create the pagination object
                $pagination = new pagination;

                // some example data
                        // set xpath search
                                $result = $xml->xpath("//property".$price.$prop_type.$bedroom_no."");

                                // initiate the search and display list
                                foreach ( $result as $list) {
                                          $propertyid   = $list->id ;
                                          $date         = $list->date;
                                          $ref          = $list->ref;
                                          $price        = $list->price;

posting smiling
Jun 22, 2008
I couldn't figure out how to make this code unmanageably nested, but that's not going to keep me from using that rightward sloping style that I'm so fond of.

Sweeper
Nov 29, 2007
The Joe Buck of Posting
Dinosaur Gum

Classicist posted:

I couldn't figure out how to make this code unmanageably nested, but that's not going to keep me from using that rightward sloping style that I'm so fond of.

but he starts indenting things that don't even need to be indented, what in the gently caress is going on!

baquerd
Jul 2, 2007

by FactsAreUseless

Sweeper posted:

but he starts indenting things that don't even need to be indented, what in the gently caress is going on!

Copy/paste that auto-indents further and then isn't corrected at a guess.

Carthag Tuek
Oct 15, 2005

Tider skal komme,
tider skal henrulle,
slægt skal følge slægters gang



Was feeling nostalgic for the late nineties and decided to look up the clusterfuck that was Hotline (basically Mac BBS software) back in the day. Most of it is management fuckups (terrible oversight) and hinks being horrible at dealing with people, but this stood out:

quote:

36. According to Mr. Spearritt, on two occasions (one in late 1996 or early 1997 and the other in August 1997) he requested Mr. Hinkley to backup all source code on Redrock's A2BNT1 UAM server. This occurred after Mr. Hinkley was unable to make a change to SPFS because he was unable to locate all the source code. In his witness statement dated 16 July 2000 (Exhibit H 16) Mr. Spearritt said:

"When a program is released to market, it is important to maintain a copy of all source code utilised in developing that program. That way, if a problem does develop in the running of the program, or if the client wants to alter the program's functionality at some future point in time, the programmer has a complete copy of source code and utilities used to create the version of the program. After the occurrence of this second incident, I told Adam that it was imperative that he kept a backed up version of each piece of production software on the A2BNT1 UAM."

37. Mr. Spearritt confirmed verbally with Mr. Hinkley about once a month that a complete copy of all source code was available on the server. Mr. Spearritt's own checks appear to have confirmed that source code was being saved on Redrock's server in a compressed file. This evidence demonstrates the confusion caused by Mr. Hinkley's failure properly to clarify his understanding of the status of the library notwithstanding that he was specifically directed to back up all source code in circumstances where the inability to access it had meant that changes could not be made to SPFS. Here was the perfect opportunity for Mr. Hinkley to explain to Redrock, if his position was then as he now contends, that in requiring him to back up the library or (which, as Mr. Hinkley must have realised, Redrock necessarily assumed was the same thing) to back up "each piece of production software", Redrock was requiring him to back up something copyright in which resided with Mr. Hinkley.

I know Subversion & git etc are all newer than this, but CVS was hardly unknown at the time. Uploading a compressed archive of the source tree each month... :psyduck:

Sinestro
Oct 31, 2010

The perfect day needs the perfect set of wheels.

Carthag posted:

Was feeling nostalgic for the late nineties and decided to look up the clusterfuck that was Hotline (basically Mac BBS software) back in the day. Most of it is management fuckups (terrible oversight) and hinks being horrible at dealing with people, but this stood out:


I know Subversion & git etc are all newer than this, but CVS was hardly unknown at the time. Uploading a compressed archive of the source tree each month... :psyduck:

We can just put "CVS :psypop:" as the response to that.

Adbot
ADBOT LOVES YOU

karoshi
Nov 4, 2008

"Can somebody mspaint eyes on the steaming packages? TIA" yeah well fuck you too buddy, this is the best you're gonna get. Is this even "work-safe"? Let's find out!

Sinestro posted:

We can just put "CVS :psypop:" as the response to that.

I got this: rsync over ssh to rsync raw CVS repos, because

Oh yeah, in the year of our lord 200X. Luckily it wasnt my team but the team sitting next to us interfacing with an outsourcer. We used the CVS protocol to update CVS repos :smugdog: (My team updated to svn after I left)

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