1926: "Bad Code"

This forum is for the individual discussion thread that goes with each new comic.

Moderators: Moderators General, Prelates, Magistrates

User avatar
squall_line
Posts: 166
Joined: Fri Mar 20, 2009 2:36 am UTC

1926: "Bad Code"

Postby squall_line » Fri Dec 08, 2017 5:09 pm UTC

Image

Alt-text: "Oh my God, why did you scotch-tape a bunch of hammers together?" "It's ok! Nothing depends on this wall being destroyed efficiently."

I've often wanted to see what would happen if all of the non-load-bearing walls in a house were taken out, but some of them have plumbing and electricity in them, so that makes it a bit tougher...

Alternately, being able to properly identify a load-bearing wall is VERY crucial when remodeling a house.

User avatar
Reka
Posts: 198
Joined: Thu Sep 20, 2012 10:21 pm UTC

Re: 1926: "Bad Code"

Postby Reka » Fri Dec 08, 2017 5:19 pm UTC

The load-bearing-wall analogy isn't quite apt: the problem (well, OK, one problem) with Cueball's "nothing depends on this" statement is that it's missing a "yet". Once you have a piece of code that does something, no matter how crappily, your boss *will* come up with some other project that needs something similar, and why don't you just use that tool you wrote a while back? Somehow "because it's crap" never carries any weight with the boss.

User avatar
The Snide Sniper
Posts: 55
Joined: Mon Mar 21, 2016 7:25 pm UTC
Location: UTC-6:00

Re: 1926: "Bad Code"

Postby The Snide Sniper » Fri Dec 08, 2017 7:11 pm UTC

The Haskell function is using regular expressions.
Also known as "RamenChef" on various other fora.
Me on: Drawception | Explain xkcd | NationStates | The Sluggite Zone | Stack Overflow

User avatar
Keyman
Posts: 294
Joined: Thu Jun 19, 2014 1:56 pm UTC

Re: 1926: "Bad Code"

Postby Keyman » Fri Dec 08, 2017 7:16 pm UTC

Knowing the only thing I know about 'coding' is what I hear here, and what can be explained down at explainxkcd when these kinds of comics get posted, and having to google terms like "Haskell function" and "parsing html", would:

"Who does he think he is, Jon Skeet?"

be an appropriate response?
A childhood spent walking while reading books has prepared me unexpectedly well for today's world.

User avatar
Reka
Posts: 198
Joined: Thu Sep 20, 2012 10:21 pm UTC

Re: 1926: "Bad Code"

Postby Reka » Fri Dec 08, 2017 8:00 pm UTC

Keyman wrote:...would: "Who does he think he is, Jon Skeet?" be an appropriate response?

Yes. Yes, it would.

:)

User avatar
Jorpho
Posts: 6194
Joined: Wed Dec 12, 2007 5:31 am UTC
Location: Canada

Re: 1926: "Bad Code"

Postby Jorpho » Fri Dec 08, 2017 8:02 pm UTC

Probably the greatest thing I have seen on StackOverflow:
You can't parse [X]HTML with regex

User avatar
Soupspoon
You have done something you shouldn't. Or are about to.
Posts: 3368
Joined: Thu Jan 28, 2016 7:00 pm UTC
Location: 53-1

Re: 1926: "Bad Code"

Postby Soupspoon » Fri Dec 08, 2017 9:46 pm UTC

squall_line wrote:I've often wanted to see what would happen if all of the non-load-bearing walls in a house were taken out, but some of them have plumbing and electricity in them, so that makes it a bit tougher...

Try removing wall. If anything goes wrong click Undo and try the same wall but with less force, until you decided to move onto another wall. Repeat.

rmsgrey
Posts: 3377
Joined: Wed Nov 16, 2011 6:35 pm UTC

Re: 1926: "Bad Code"

Postby rmsgrey » Fri Dec 08, 2017 11:33 pm UTC

squall_line wrote:I've often wanted to see what would happen if all of the non-load-bearing walls in a house were taken out, but some of them have plumbing and electricity in them, so that makes it a bit tougher...

Alternately, being able to properly identify a load-bearing wall is VERY crucial when remodeling a house.


If you take out the wrong wall, all remaining walls cease to be load-bearing...

keldor
Posts: 63
Joined: Thu Jan 26, 2012 9:18 am UTC

Re: 1926: "Bad Code"

Postby keldor » Sat Dec 09, 2017 3:57 am UTC

rmsgrey wrote:
squall_line wrote:I've often wanted to see what would happen if all of the non-load-bearing walls in a house were taken out, but some of them have plumbing and electricity in them, so that makes it a bit tougher...

Alternately, being able to properly identify a load-bearing wall is VERY crucial when remodeling a house.


If you take out the wrong wall, all remaining walls cease to be load-bearing...


Problem solved!

User avatar
chridd
Has a vermicelli title
Posts: 818
Joined: Tue Aug 19, 2008 10:07 am UTC
Location: ...Earth, I guess?
Contact:

Re: 1926: "Bad Code"

Postby chridd » Sat Dec 09, 2017 4:04 am UTC

Jorpho wrote:Probably the greatest thing I have seen on StackOverflow:
You can't parse [X]HTML with regex
For XML:

Code: Select all

<[:A-Z_a-z\xc0-\xd6\xd8-\xf6\xf8\x{2ff}\x{370}-\x{37d}\x{37f}-\x{1fff}\x{200c}\x{200d}\x{2070}-\x{218f}\x{2c00}-\x{2fef}\x{3001}-\x{d7ff}\x{f900}-\x{fdcf}\x{fdf0}-\x{fffd}\x{10000}\x{effff}][-.:0-9A-Z_a-z\xb7\xc0-\xd6\xd8-\xf6\xf8\x{36f}\x{370}-\x{37d}\x{37f}-\x{1fff}\x{200c}\x{200d}\x{203f}-\x{2040}\x{2070}-\x{218f}\x{2c00}-\x{2fef}\x{3001}-\x{d7ff}\x{f900}-\x{fdcf}\x{fdf0}-\x{fffd}\x{10000}\x{effff}]*(?:\s+[:A-Z_a-z\xc0-\xd6\xd8-\xf6\xf8\x{2ff}\x{370}-\x{37d}\x{37f}-\x{1fff}\x{200c}\x{200d}\x{2070}-\x{218f}\x{2c00}-\x{2fef}\x{3001}-\x{d7ff}\x{f900}-\x{fdcf}\x{fdf0}-\x{fffd}\x{10000}\x{effff}][-.:0-9A-Z_a-z\xb7\xc0-\xd6\xd8-\xf6\xf8\x{36f}\x{370}-\x{37d}\x{37f}-\x{1fff}\x{200c}\x{200d}\x{203f}-\x{2040}\x{2070}-\x{218f}\x{2c00}-\x{2fef}\x{3001}-\x{d7ff}\x{f900}-\x{fdcf}\x{fdf0}-\x{fffd}\x{10000}\x{effff}]*\s*=\s*(?:"(?:[^<&"]|&[:A-Z_a-z\xc0-\xd6\xd8-\xf6\xf8\x{2ff}\x{370}-\x{37d}\x{37f}-\x{1fff}\x{200c}\x{200d}\x{2070}-\x{218f}\x{2c00}-\x{2fef}\x{3001}-\x{d7ff}\x{f900}-\x{fdcf}\x{fdf0}-\x{fffd}\x{10000}\x{effff}][-.:0-9A-Z_a-z\xb7\xc0-\xd6\xd8-\xf6\xf8\x{36f}\x{370}-\x{37d}\x{37f}-\x{1fff}\x{200c}\x{200d}\x{203f}-\x{2040}\x{2070}-\x{218f}\x{2c00}-\x{2fef}\x{3001}-\x{d7ff}\x{f900}-\x{fdcf}\x{fdf0}-\x{fffd}\x{10000}\x{effff}]*;|&#[0-9]+;|&#x[0-9a-fA-F]+;)*"|'(?:[^<&']|&[:A-Z_a-z\xc0-\xd6\xd8-\xf6\xf8\x{2ff}\x{370}-\x{37d}\x{37f}-\x{1fff}\x{200c}\x{200d}\x{2070}-\x{218f}\x{2c00}-\x{2fef}\x{3001}-\x{d7ff}\x{f900}-\x{fdcf}\x{fdf0}-\x{fffd}\x{10000}\x{effff}][-.:0-9A-Z_a-z\xb7\xc0-\xd6\xd8-\xf6\xf8\x{36f}\x{370}-\x{37d}\x{37f}-\x{1fff}\x{200c}\x{200d}\x{203f}-\x{2040}\x{2070}-\x{218f}\x{2c00}-\x{2fef}\x{3001}-\x{d7ff}\x{f900}-\x{fdcf}\x{fdf0}-\x{fffd}\x{10000}\x{effff}]*;|&#[0-9]+;|&#x[0-9a-fA-F]+;)*'))*\s*>
XML itself isn't regular, but the syntax for opening tags is. (Note: does not check all well-formedness constraints.)

Most of that is checking that all names have the right characters. If we assume that the document is well-formed (which is usually a valid assumption—usually the goal is to extract some information from a document, not check whether it's valid, so it usually doesn't matter if the code catches all possible errors):

Code: Select all

<[^<&='"\s]+(?:\s+[^<&='"\s]+\s*=\s*(?:"[^<"]*"|'[^<']*'))*\s*>
~ chri d. d. /tʃɹɪ.di.di/ (Phonotactics, schmphonotactics) · she(?)(?(?)(?))(?(?(?))(?))(?) · Forum game scores
mittfh wrote:I wish this post was very quotable...
flicky1991 wrote:In both cases the quote is "I'm being quoted too much!"

CharonPDX
Posts: 58
Joined: Wed Apr 27, 2011 4:55 am UTC

Re: 1926: "Bad Code"

Postby CharonPDX » Mon Dec 11, 2017 12:32 pm UTC

In the past, I ran up against Microsoft Excel's individual-cell character limit often when creating monster formulas for various forms of data analysis.

It was completely, absolutely, 100% unreadable mess. Some individual data analyses required the data table to have lots of ugly parsing necessary, as the data coming in was mixed text and numeric data, with no simple/easy way to chop it up in to label+data, I had to modify the monster formulas every time I discovered we were getting a new format of incoming data. ("Oh, look, someone threw a number in the label of that one, that's throwing off my LOOKUP...")

In the end, I think I had at one point, to aggregate one type of data from the data table (50ish columns, a few hundred rows,) I had to have an additional few dozen "data lookup" columns to parse each row's information to something I could formulize, then some ridiculously hacked up lookup/find/mid monstrosities to extort (sorry, extract) usable data out of it.

To produce a "summary" page that contained about a dozen values.

Oh, and the data came in daily, in the form of a text file that in theory should have been a CSV, but often the system that generated it munged that up. So I had a macro that turned the daily "CSV" in to my finished spreadsheet, by adding my extra "data lookup" columns, filling in the formulas in the right cells, autofilling them down, creating the "working" sheet, adding all the formulas there, creating the summary page, and adding all the formulas and formatting to it.

Yeah, I probably spent 40-50 hours creating this monstrosity, but by the time I was done, it only took about 2 minutes to create this daily summary page, when previously it was a 2-3 man-hour process, split among three people. Don't even get me started on the weekly/monthly report spreadsheets... (Similar, but with *WAAAAY* more data points/rows.) I wish I had a copy of those ridiculous monsters.

So, yeah, sometimes duct-taping hammers together to start chucking them at a non-load-bearing-wall can be useful.


Return to “Individual XKCD Comic Threads”

Who is online

Users browsing this forum: Google Feedfetcher, Heimhenge and 43 guests