code logs -> 2007 -> Tue, 24 Jul 2007< code.20070723.log - code.20070725.log >
--- Log opened Tue Jul 24 00:00:01 2007
00:43 ChalcyLaptop [~Forjadon@Nightstar-17168.ue.woosh.co.nz] has quit [Ping Timeout]
00:49 Forjadon [~Forjadon@Nightstar-17168.ue.woosh.co.nz] has joined #code
00:49 mode/#code [+o Forjadon] by ChanServ
00:57 Forjadon is now known as ChalcyLaptop
01:08 AnnoDomini [~farkoff@Nightstar-29028.neoplus.adsl.tpnet.pl] has quit [Quit: The screams are not loud enough.]
02:16 KBot [~fark.off@87.72.35.ns-3885] has joined #Code
02:16 KBot [~fark.off@87.72.35.ns-3885] has quit [Client exited]
03:24 ChalcyLaptop [~Forjadon@Nightstar-17168.ue.woosh.co.nz] has quit [Ping Timeout]
03:31 ReivZzz is now known as Reiver
03:45 Netsplit Blargh.CA.US.Nightstar.Net <-> Troika.TX.US.Nightstar.Net quits: @Pi, Raif, EvilDarkLord, +KarmaBot, Vornicus-Latens, @Serah, Thaqui, jerith, @ToxicFrog, Reiver, (+1 more, use /NETSPLIT to show all of them)
03:45 Netsplit over, joins: @Serah, +KarmaBot, @ToxicFrog, EvilDarkLord
03:46 Netsplit over, joins: Pi, Chalain
03:46 mode/#code [+o Pi] by ChanServ
03:46 Netsplit over, joins: Raif, Reiver
03:46 Netsplit over, joins: Vornicus-Latens
03:46 mode/#code [+o Chalain] by ChanServ
03:46 Netsplit over, joins: Thaqui
03:46 mode/#code [+o Reiver] by ChanServ
03:46 mode/#code [+o Thaqui] by ChanServ
03:46 Raif [~corvusign@Admin.Nightstar.Net] has quit [Killed (NickServ (GHOST command used by Raif_))]
03:46 jerith [~jerith@Nightstar-21563.slipgate.za.net] has joined #code
03:46 Raif_ [~corvusign@Nightstar-7926.hsd1.wa.comcast.net] has joined #Code
03:46 Raif_ is now known as Raif
03:46 Thaqui [~Thaqui@Nightstar-17986.jetstream.xtra.co.nz] has quit [Ping Timeout]
03:46 ReivClass [~reaverta@Admin.Nightstar.Net] has joined #Code
03:47 Reiver [~reaverta@Admin.Nightstar.Net] has quit [Ping Timeout]
03:47 jerith is now known as NSGuest-345
03:47 ReivClass is now known as Reiver
03:54 Thaqui [~Thaqui@Nightstar-17986.jetstream.xtra.co.nz] has joined #code
03:54 mode/#code [+o Thaqui] by ChanServ
04:31 Netsplit DeepThought.NY.US.Nightstar.Net <-> Troika.TX.US.Nightstar.Net quits: @Pi, Raif, Vornicus-Latens, Reiver, NSGuest-345, @Chalain
04:31 Netsplit over, joins: Pi, Chalain, Vornicus-Latens
04:31 mode/#code [+o Pi] by ChanServ
04:31 Netsplit over, joins: Raif
04:31 Netsplit over, joins: NSGuest-345, Reiver
04:31 mode/#code [+o Chalain] by ChanServ
04:31 Reiver [~reaverta@Admin.Nightstar.Net] has quit [Ping Timeout]
04:31 mode/#code [+o Reiver] by ChanServ
04:31 Raif [~corvusign@Nightstar-7926.hsd1.wa.comcast.net] has quit [Killed (NickServ (GHOST command used by Raif_))]
04:32 Raif_ [~corvusign@Nightstar-7926.hsd1.wa.comcast.net] has joined #Code
04:32 Reiver [~reaverta@Admin.Nightstar.Net] has joined #Code
04:32 mode/#code [+o Reiver] by ChanServ
04:32 Raif_ is now known as Raif
04:32 NSGuest-345 [~jerith@Nightstar-21563.slipgate.za.net] has quit [Ping Timeout]
04:32 jerith [~jerith@Nightstar-21563.slipgate.za.net] has joined #code
04:33 jerith is now known as NSGuest-347
04:33 Forjadon [~Forjadon@Nightstar-17168.ue.woosh.co.nz] has joined #code
04:33 mode/#code [+o Forjadon] by ChanServ
04:37 Forjadon is now known as ChalcyLaptop
04:39 Netsplit DeepThought.NY.US.Nightstar.Net <-> Troika.TX.US.Nightstar.Net quits: @Pi, Raif, @ChalcyLaptop, Vornicus-Latens, @Reiver, NSGuest-347, @Chalain
04:40 Netsplit over, joins: Pi, Chalain, Vornicus-Latens
04:40 mode/#code [+o Pi] by ChanServ
04:40 Netsplit over, joins: Raif, Reiver
04:40 mode/#code [+o Chalain] by ChanServ
04:40 Raif [~corvusign@Nightstar-7926.hsd1.wa.comcast.net] has quit [Killed (NickServ (GHOST command used by Raif_))]
04:40 mode/#code [+o Reiver] by ChanServ
04:40 Raif_ [~corvusign@Nightstar-7926.hsd1.wa.comcast.net] has joined #Code
04:40 Raif_ is now known as Raif
04:40 ReivClass [~reaverta@IRCop.Nightstar.Net] has joined #Code
04:40 Pi [~sysop@Nightstar-6875.hsd1.wa.comcast.net] has quit [Ping Timeout]
04:40 Forjadon [~Forjadon@Nightstar-17168.ue.woosh.co.nz] has joined #code
04:40 mode/#code [+o Forjadon] by ChanServ
04:41 Reiver [~reaverta@Admin.Nightstar.Net] has quit [Ping Timeout]
04:41 ReivClass is now known as Reiver
04:41 Pi [~sysop@Nightstar-6875.hsd1.wa.comcast.net] has joined #code
04:41 mode/#code [+o Pi] by ChanServ
04:42 jerith [~jerith@Nightstar-21563.slipgate.za.net] has joined #code
04:43 jerith is now known as NSGuest-348
04:50 Vornicus-Latens is now known as Vornicus
04:55 Forjadon is now known as ChalcyLaptop
05:26 Serah [~Z@87.72.35.ns-3885] has quit [Connection reset by peer]
05:28 Serah [~Z@87.72.35.ns-3885] has joined #Code
05:28 mode/#code [+o Serah] by ChanServ
05:57 Forj [~Forj@Nightstar-17168.ue.woosh.co.nz] has joined #code
06:28 Vornotron [~vorn@64.252.97.ns-4252] has joined #code
06:29 Vornicus [~vorn@Admin.Nightstar.Net] has quit [Ping Timeout]
06:45 Vornotron [~vorn@64.252.97.ns-4252] has quit [Connection reset by peer]
06:46 Vornotron [~vorn@69.0.81.ns-26841] has joined #code
07:09 NSGuest-348 is now known as jerith
07:17 Vornotron is now known as Vornicus
08:01
< Vornicus>
eew.
08:01
< Vornicus>
er, wrong channel. I'm doing that a lot lately.
08:01 * ChalcyLaptop cookies Vorn
08:01 * Vornicus nrom.
08:02
< Reiver>
eew?
08:02
< Vornicus>
Discussing Raif's evilgiant character sheet
08:13 ChalcyLaptop [~Forjadon@Nightstar-17168.ue.woosh.co.nz] has quit [Ping Timeout]
08:16 ChalcyLaptop [~Forjadon@Nightstar-17168.ue.woosh.co.nz] has joined #code
08:45 You're now known as TheWatcher
09:22 * Reiver starts downloading Python, realising it might be useful if he's going to fiddle with Python code some day. ¬¬
09:22
< Vornicus>
pff
09:44 * Vornicus fiddles with things, tries to figure out how to make the files that TF made.
09:44
< Vornicus>
that TF made for SDL that is.
10:56 Forj [~Forj@Nightstar-17168.ue.woosh.co.nz] has quit [Quit: Gone]
11:09 ChalcyLaptop [~Forjadon@Nightstar-17168.ue.woosh.co.nz] has quit [Quit: Leaving]
11:15 Serah [~Z@87.72.35.ns-3885] has quit [Ping Timeout]
11:15 KBot [~fark.off@87.72.35.ns-3885] has joined #Code
11:15 KarmaBot [~fark.off@87.72.35.ns-3885] has quit [Connection reset by peer]
11:16 Serah [~Z@87.72.35.ns-3885] has joined #Code
11:16 mode/#code [+o Serah] by ChanServ
11:16 KBot is now known as KarmaBot
11:17 gnolam [lenin@Nightstar-13557.8.5.253.se.wasadata.net] has joined #Code
11:17 mode/#code [+o gnolam] by ChanServ
11:24 KarmaBot [~fark.off@87.72.35.ns-3885] has quit [Connection reset by peer]
11:24 Serah [~Z@87.72.35.ns-3885] has quit [Killed (NickServ (GHOST command used by Ev3))]
11:24 Serah [~Z@87.72.35.ns-3885] has joined #Code
11:24 mode/#code [+o Serah] by ChanServ
11:25 KarmaBot [~fark.off@87.72.35.ns-3885] has joined #Code
11:25 mode/#code [+v KarmaBot] by ChanServ
12:00
< Vornicus>
Reiver, how many phone numbers do you have?
12:00
< Reiver>
2.
12:01
< Vornicus>
A home phone, and a cell phone?
12:01
< Reiver>
Correct.
12:01
< Reiver>
(I may soon end up with three.)
12:01
< Vornicus>
Okay. Now, you get a job in an office.
12:01
< Vornicus>
That's a third one.
12:01
< Vornicus>
And then you have a fax machine at your office, too, so that's four.
12:02
< Reiver>
Okay.
12:03
< Vornicus>
Then you might get a fax machine at home, so that's five. Then you get a Skype number, and a pager from work, and a second line at home, and a second job, and...
12:03
< Vornicus>
This is starting to get silly.
12:03
< Vornicus>
So, how many columns do you dedicate in your "person" table to phone numbers?
12:04
< Reiver>
You don't; you make a linked table to start with.
12:04
< Vornicus>
Right, but let's be idiots for a while.
12:04
< Reiver>
...Mind you, I'm a sucker for those things. >.>
12:04
< Reiver>
Okay.
12:04
< Reiver>
(I tend to, uh, overdo those.)
12:05
< Vornicus>
Let's first try making a whole bunch of columns, one for each kind of phone number we can think of.
12:05
< Reiver>
Right.
12:05
< Vornicus>
and it's the 70s, so people don't have cell phones.
12:06
< Vornicus>
...and then cell phones come along.
12:06
< Reiver>
And then they suddenly become Popular.
12:06
< Vornicus>
so we have to go through and add a whole column to our table.
12:06
< Reiver>
And you go Oh Bugger.
12:06
< Vornicus>
This, especially with older database systems, was an incredible pain in the ass.
12:07
< Vornicus>
And then people start getting skype and that sort of crap, eventually, so you keep having to change it, and each new column needs the appropriate validation rules.
12:07
< Reiver>
Right.
12:08
< Vornicus>
Okay, so that design sucks.
12:08
< Vornicus>
Let's do it differently! Let's put all our phone numbers in a single column, and separate it by commas or something!
12:09
< Vornicus>
...and then you have to keep changing the validation rule every time someone comes up with a new kind of phone number, and you can't extract individual numbers without some awesome text processing.
12:09
< Vornicus>
This table, it isn't in first normal form - you have single records with lists in them.
12:10 * Reiver nods.
12:10
< Vornicus>
So this is the first rule. Don't have single records with lists in them, no matter how you slice the list.
12:10 * Reiver nod.
12:11
< Vornicus>
Apply it, and you get an index table: a table that says "this person has this number for his work number."
12:11
< Vornicus>
(it's got a bit more than that in there, but you get the idea)
12:12
< Vornicus>
And when you have a database that follows that rule, it is said to be in first normal form.
12:13
< Vornicus>
(there are some other minor rules - the rows and columns are each in no special order, and there are no duplicate rows, but you get the idea)
12:14
< Reiver>
(Yep.)
12:14 * Reiver has been taught some of this. Vaugely.
12:14
< Vornicus>
I think I went through this with you before, but.
12:14 * Reiver has a suspicion it was in that class that had a lot of 8AM lectures ¬¬
12:15
< Vornicus>
heh.
12:16 * Vornicus fiddles, tries to find a decent example for the next one.
12:21
< Vornicus>
oh, the obvious one.
12:21
< Vornicus>
Okay, you're making an ordering system.
12:23
< Vornicus>
So you have an order, and an order has a bunch of items in it.
12:23
< Vornicus>
Call the pizza joint and say "I want a large pepperoni pizza and a bottle of coke", and now you have two rows in a table, one for each item.
12:24
< Vornicus>
But let's be stupid for a moment, and put all the information for the order - the address it should be delivered to, the person who called, etc etc - into each row with the item.
12:26
< Vornicus>
...and then you realize that you wrote down the phone number wrong.
12:26
< Vornicus>
So you go to change it... and have to change it all over the place.
12:26
< Vornicus>
This sucks.
12:26
< Vornicus>
Link table time!
12:26 * Reiver nods.
12:27
< Vornicus>
Now, you have an order table, and an order-items table.
12:27
< Vornicus>
and the order table has all the goodies in it like the address and the phone number, and the order-items table says what order the item is with, and what item you're getting.
12:28
< Vornicus>
And now you're in second normal form: nothing in either table depends on only /part/ of the primary key.
12:29
< Vornicus>
Now, let's look at that order table, the one with the addresses in it.
12:30
< Reiver>
Only part of the primary key?
12:30 * Reiver never did get that bit.
12:30
< Vornicus>
the US postal service has a thing that, given an address without a zip code, can determine the zip code. Why, then, are we storing the zip code? We can just ask the postal service.
12:30
< Vornicus>
In a minute I'm going to work backwards.
12:30
< Reiver>
OK.
12:30
< Vornicus>
And then you'll see what I mean, because it's pretty dramatic.
12:30
< Reiver>
OK.
12:31
< Reiver>
:)
12:31
< Vornicus>
The zip code depends on something that's not part of the primary key of this table - the address.
12:32
< Vornicus>
This sucks, because we can then get the zip code wrong (not that this is really a big deal, because the driver doesn't care, and the postal service can just look and get it right)
12:33
< Vornicus>
So instead we have a table that relates zip codes to addresses, with address as the primary key, right/
12:33
< Vornicus>
right?
12:33
< Vornicus>
beuller?
12:33
< Vornicus>
...well, no, technically, we don't.
12:33
< Vornicus>
because god that's a pain in the ass.
12:33
< Reiver>
OK.
12:34
< Vornicus>
In fact, /that/ table is hard to create in even /second/ normal form.
12:34
< Reiver>
(We don't actually have zip codes, so I'm mostly nodding and smiling.)
12:34
< Vornicus>
do you have anything resembling zip or postal codes?
12:35
< Vornicus>
Well, whichever.
12:35
< Reiver>
Well, I get the idea.
12:35
< Vornicus>
Let's take my zip code, 06615.
12:35
< Reiver>
It's a code that they use for easier sorting of mail.
12:35
< Reiver>
Removes chances of doubling up of addresses due to street names etc
12:36
< Vornicus>
I can look at that zip code and tell approximately where I live, and a decent portion of my address. With the 9-digit zip code (06615-5728) I can even tell what street I'm on, and what side of the street.
12:36
< Reiver>
...I did not know they were that good. Okay.
12:36
< Vornicus>
The first thing is this: /all the zip codes in New England start with 0/.
12:37
< Vornicus>
So I know that an address in new england starts with 0.
12:38
< Reiver>
Ahh. Okay.
12:38
< Reiver>
(So they're like phone numbers, which hold a consistent structure.)
12:38
< Vornicus>
Then, the second thing is this: /all the zip codes in connecticut start with 06/.
12:39
< Vornicus>
so just by looking at /part/ of my address, I can determine part of the zip code.
12:39
< Reiver>
Right.
12:39
< Vornicus>
But it gets even worse!
12:40
< Vornicus>
There are distribution centers that use three-digit codes. Bridgeport has 066, New Haven has 065, Wallingford has 064...
12:42
< Vornicus>
so I know that a zip code that starts with 066 is somewhere around bridgeport, closer to it than to stamford (west) or to new haven (east) or to waterbury (north)
12:42
< Reiver>
So it's a composite key, then?
12:42
< Vornicus>
then the 4-digit level doesn't do you much; Trumbull, Stratford, and eastern Bridgeport get 0661, but it's not very smooth.
12:43
< Vornicus>
The point here is that /only part of the address/ gets you a lot of information.
12:43 * Reiver nod.
12:45
< Vornicus>
And that's what second normal form is designed to prevent.
12:45
< Vornicus>
Anyway.
12:45
< Reiver>
Because that means there's too much information in your key to start with?
12:46
< Vornicus>
Not necessarily - you may have the right amount of information in your key, but too much information in the row as a whole - the address being in every item record in an order, for instance; you need the item and the order number, but the address should be somewhere else.
12:47
< Reiver>
Right
12:49
< Vornicus>
But, anyway, back to third normal form.
12:49
< Vornicus>
The point of third normal form is that you can't have anything that depends on something other than the key.
12:50
< Reiver>
Because it all needs to link back to the origional key, else you can have things break.
12:50
< Reiver>
And you should be able to find a record with just the key - and vice versa.
12:50
< Vornicus>
Right.
12:51
< Vornicus>
now, there's a slightly stricter form of third normal form, where nothing /in the key/ can depend on something /outside the key/.
12:51
< Reiver>
...okay
12:51
< Vornicus>
I can't actually think of anything that violates that, but that's because it's rare.
12:51
< Vornicus>
this is called Boyce-Codd Normal Form.
12:52
< Reiver>
Okay.
12:53
< Vornicus>
Actually the whole thing is the whole key is independent of anything, and everything outside the key is dependent only on the key.
12:53
< Vornicus>
--independent of anything else in the table. You can use parts of the key as a foreign key.
12:55
< Vornicus>
Okay, now, fourth normal form.
12:56
< Vornicus>
You have phone numbers /and/ email addresses, right?
12:57
< Vornicus>
and these phone numbers and email addresses have little to do with each other, right?
12:57
< Reiver>
Except that they're both contact details for one person.
12:57
< Vornicus>
Well, sure.
12:57
< Reiver>
Otherwise, yes.
13:00
< Vornicus>
but it seems someone has been a sillyhead, and wanted to know what email addresses and phone numbers were associated with each other (by being for the same person) but didn't want to go to multiple tables to do it.
13:04
< Vornicus>
So what they did was they made it so each row in their email/phone number-to-person link table has both an email address and a phone number, and they have every possible email/phone number pair.
13:04
< Vornicus>
eeeeeeeeeeeeeeew.
13:05
< Vornicus>
So instead you have a table /just/ for phone numbers, and a table /just/ for email addresses.
13:06
< Vornicus>
Which is much easier to deal with.
13:06
< Vornicus>
So fourth normal form is just: each independent listy thing should be in a different table.
13:09
< Vornicus>
fifth normal form is much harder to describe, and I can't actually think of any examples - like BCNF, it's rare for a thing to be 4th normal form but not 5th.
13:09 * Reiver nods.
13:14
< Vornicus>
the point, though, is to reduce redundancy more - you have many-many relationships that are closely related, but there's constraints on the relationship that make it so you end up with a lot of redundant information unless you separate the various relationships.
13:16
< Vornicus>
that statement was a load of gobbledygook.
13:16
< Reiver>
It sounded like it came from a marketer, certainly~
13:16
< Vornicus>
yeah.
13:17
< Vornicus>
Okay, the thing about fourth normal form is it only works on independent relationships - email addresses and phone numbers.
13:17 Thaqui [~Thaqui@Nightstar-17986.jetstream.xtra.co.nz] has left #code [Leaving]
13:19
< Vornicus>
But what if they /are/ related? What if you want to, after getting an email from someone's work address, call them on the phone? Obviously you'd want to call their work phone.
13:20
< Vornicus>
Well, you could have them in teh same table - this phone number is associated with this email address, etc
13:20
< Vornicus>
OR
13:21 * Serah sprinkles Vorn with sugar.
13:21
< Vornicus>
you could say "this phone number is a work phone number; this email address is a work email address" and then go "to call someone about something in a work email, call a work number."
13:23
< Vornicus>
Getting to 5NF can be done in a lot of different ways, it's not nearly as simple as the others.
13:26
< Vornicus>
And, finally, there is one that is kind of independent of the others.
13:26
< Vornicus>
Domain-Key Normal Form says that there should be only two constraints on the data in a database.
13:27
< Vornicus>
One is Domain - any individual column can take only certain kinds of data, in a certain range, etc, and this is independent of anything else in the database.
13:30
< Vornicus>
And the other is Key - a column or set of columns may have a constraint that their data must exist as a primary key in another table.
13:32
< Vornicus>
And that's it.
13:33
< Reiver>
Hmn.
13:33
< Reiver>
The funny thing is, this is all pretty straightforward, logical stuff.
13:33
< Vornicus>
IYep.
13:33
< Reiver>
And yet I wonder how long it took for them to work it all out.
13:34
< Vornicus>
To make it general and say "this is a rule!" probably took a while.
13:34
< Reiver>
Yeah
13:36
< Vornicus>
But then there's the complex math behind all this, and optimizations based on the assumption that things are in a high normal form.
13:37
< Vornicus>
also, I appear to be sugar-coated.
13:37
< EvilDarkLord>
But that can be left for the RDBMS to worry about mostly, right?
13:37
< Vornicus>
Sure. But you should still design to it.
13:37
< Reiver>
EDL: Anyone touching a database needs to take it into account when designing a database (AKA anything more than a boring ol' list.)
13:39
< EvilDarkLord>
Point being: Once you have designed by 5NF you can pat yourself on the back and let the RDBMS worry about all the details of how it shuffles around the data while making a query.
13:39
< Vornicus>
Yep.
13:40
< Vornicus>
But to design the database you need to know what the heck you're aiming at.
13:40
< Vornicus>
And the higher normal form that applies to your database, the easier it is to design the query to get what you want.
13:43
< Vornicus>
The whole point of database normalization is to make it easier and safer to manipulate the data.
13:44
< EvilDarkLord>
Yeah. And saving RAM space :)
13:46
< EvilDarkLord>
(Which is why I tend to abhor strings as primary keys, preferring to use an integer and link to the table with the strings as needed)
13:47
< Vornicus>
Lots, and lots, and lots of cool things you can do with properly normalized data.
13:49
< EvilDarkLord>
Where have you gotten with your settles of catan game, by the way?
13:49
< EvilDarkLord>
*settlers
13:49
< Vornicus>
Not that far; I got very distracted, and I'm only just now getting back to it.
13:53
< Vornicus>
And every time I do I go "god I don't want to use Rails for this" because I keep ending up in the same place - fighting the built in DB model because I confuse it with my schema.
13:54
< Vornicus>
Which is how I got started on this discussion anyway
13:54
< Reiver>
And yet Rails is Seductive and keeps dragging you back in?
13:55
< Vornicus>
It does a lot of things for me, and if I can convince it to use my schema, I don't have to think about it after that.
13:58
< EvilDarkLord>
Can you write your own db functions, or would that be a lot of bother?
13:58
< Vornicus>
It would be a hell of a lot of bother.
14:11 MyCatVerbs [~rb6822@Nightstar-18641.cs.bris.ac.uk] has joined #code
14:27
<@ToxicFrog>
Vornicus: what was this about SDL?
14:28
< Vornicus>
I'm trying to figure out how you wrote the lua bindings for SDL, so I can do the same for OpenGL
14:29
<@ToxicFrog>
It all uses tolua++ - the module files define what functions and data structures to bind, then tolua++ is run to generate the actual C code.
14:43 DiceBot [~Reiver@Nightstar-28711.ubs-dsl.xnet.co.nz] has joined #Code
14:45 DiceBot [~Reiver@Nightstar-28711.ubs-dsl.xnet.co.nz] has quit [Quit: DiceBot: based on AnnoDomini's KarmaBot. [manual quit.]]
14:46 DiceBot [~Reiver@Nightstar-28711.ubs-dsl.xnet.co.nz] has joined #Code
14:49 * ToxicFrog throttles getopts
14:51 RBot [~Reiver@Nightstar-28711.ubs-dsl.xnet.co.nz] has joined #Code
14:51 RBot [~Reiver@Nightstar-28711.ubs-dsl.xnet.co.nz] has left #Code []
14:52 DiceBot [~Reiver@Nightstar-28711.ubs-dsl.xnet.co.nz] has quit [Quit: DiceBot: based on AnnoDomini's KarmaBot. [manual quit.]]
14:53 DiceBot [~Reiver@Nightstar-28711.ubs-dsl.xnet.co.nz] has joined #Code
14:55 DiceBot [~Reiver@Nightstar-28711.ubs-dsl.xnet.co.nz] has quit [Quit: Forgive the join/quit spam. Reiver is bugtesting.]
14:56 DiceBot [~Reiver@Nightstar-28711.ubs-dsl.xnet.co.nz] has joined #Code
14:57 DiceBot [~Reiver@Nightstar-28711.ubs-dsl.xnet.co.nz] has quit [Quit: DiceBot: based on AnnoDomini's KarmaBot.]
14:58 DiceBot [~Reiver@Nightstar-28711.ubs-dsl.xnet.co.nz] has joined #Code
15:25
<@ToxicFrog>
Why does getopts contain so much hate ;.;
15:32
<@Serah>
RAWR?
15:35
< MyCatVerbs>
int inchar; while ((inchar = getopts(argc,argv,"dDgGi:t:p:?")) != -1) { switch (inchar) { case 'd': /* stuff */ break; ...
15:36
< MyCatVerbs>
How would one go about creating a version of getopts that actually contains hatred?
15:37
<@ToxicFrog>
It's not the API that contains hatred.
15:38
<@ToxicFrog>
It's the implementation.
15:38
< MyCatVerbs>
Segfault bugs?
15:38
<@ToxicFrog>
This is the kind of thing that looks like it's a simple application of regexes, but inevitably turns into a FSM.
15:38
< MyCatVerbs>
Oh, you're writing it yourself.
15:39
<@ToxicFrog>
Yes.
15:39
< MyCatVerbs>
Then you're going to need an awkward FSM. Regexes won't handle that.
15:39
< Reiver>
Flying Spagetti Monsters?
15:40
< MyCatVerbs>
Finite State Machine.
15:40
<@ToxicFrog>
Finite State Machine.
15:40
< Reiver>
Oh.
15:40
< Reiver>
Well, I guess it makes more sense. But the mental imagery is much less hilarious... >.>
15:41
< MyCatVerbs>
You could build a FSM from a FSM. Just put a conveyor belt under it and attach
15:41
< MyCatVerbs>
*and attach pens to all of its noodly appendages.
15:42
< Reiver>
Okay, that mental imagery is even funnier. >.>
15:42
< MyCatVerbs>
\o/
15:52
<@ToxicFrog>
There we go.
15:52
<@ToxicFrog>
> for optopt,optarg in getopts("ab:c?", "-abc", "-a", "foo", "-b", "bar", "-cbaz", "-c", "-bquux") do print(optopt,optarg) end
15:52
<@ToxicFrog>
a nil
15:52
<@ToxicFrog>
b c
15:52
<@ToxicFrog>
a nil
15:52
<@ToxicFrog>
true foo
15:52
<@ToxicFrog>
b bar
15:52
<@ToxicFrog>
c baz
15:52
<@ToxicFrog>
c nil
15:52
<@ToxicFrog>
b quux
15:53
< Vornicus>
"ab:c?" ?
15:53
<@ToxicFrog>
That's the argspec. "a" indicates a valid flag, "b:" indicates a valid flag that must be followed by an argument, "c?" a valid flag that can optionally be followed by an argument.
15:54
< Vornicus>
aha.
15:54
< Vornicus>
...this must be some scary code.
15:54
<@ToxicFrog>
Sixty-eight lines, three subfunctions, a coroutine, and flow control structures nested six deep.
15:54
< Vornicus>
...fun.
15:54
<@ToxicFrog>
I'm working on cleaning it up.
15:58
<@ToxicFrog>
It's still not as scary as the original getopts(), though.
16:00
<@ToxicFrog>
Which is not only written in C, but permutes the contents of argv.
16:00
<@ToxicFrog>
And communicates with the caller using global variables.
16:02
< Vornicus>
:(
16:03
<@ToxicFrog>
This is what happens when you try to implement an iterator that returns multiple values in a language that supports neither.
16:04
< Vornicus>
yeah, uh
16:06
<@ToxicFrog>
(not sure why there isn't a getopt_r, though. Some nod toward threadsafety would be nice.)
16:06
< Vornicus>
getopt_r?
16:07
< MyCatVerbs>
Vornicus: think, int function (arguments,morearguments); /* non thread-safe, uses global variables */
16:07
<@ToxicFrog>
Many (?most) GNU and POSIX functions have _r variants, which take and modify a reentrancy function rather than modifying global state.
16:07
<@ToxicFrog>
Thus, if you want threadsafety, you use foo_r(foo_state *, ...) rather than foo(...)
16:08
< MyCatVerbs>
Vornicus: then, int function_r (struct lumpofdata* x, arguments, morearguments); /* all those global and static variables pushed out into the struct lumpofdata */
16:08
< MyCatVerbs>
foo_state, I like it. ^^
16:08
<@ToxicFrog>
Err. Reentrancy function? Reentrancy structure.
16:08
<@ToxicFrog>
See, for example, the man pages for rand and rand_r
16:10
< Vornicus>
ah, I see
16:24
<@ToxicFrog>
It is now 90 lines and contains four subfunctions, but is much more readable.
16:28
<@ToxicFrog>
So, what does this leave.
16:28
<@ToxicFrog>
A more elegant and/or faster version of memoize;
16:29
<@ToxicFrog>
String.interpolate;
16:29
<@ToxicFrog>
...and that's it.
16:29
<@ToxicFrog>
Cool.
16:36 MyCatVerbs [~rb6822@Nightstar-18641.cs.bris.ac.uk] has quit [Quit: Swim, swim, hungry!]
16:57
<@ToxicFrog>
string.interpolate done, I think.
16:58
< Vornicus>
what's string.interpolate do?
17:00
<@ToxicFrog>
You pass it a string containing $(...) sequences and a table.
17:00
<@ToxicFrog>
It resolves those sequences in terms of the table, recursively, and returns a copy of the string with all sequences expanded.
17:01
<@ToxicFrog>
McM and I came up with the original design, for use in Spellcast.
17:02
<@ToxicFrog>
So that you could write for a cast message, say: "$(caster) casts $(spell) $(target) (with $(hands))"
17:03
<@ToxicFrog>
And the stuff inside the $() is evaluated as a Lua expression.
17:04
<@ToxicFrog>
In effect, it implements bash's $() notation as a Lua function call.
17:04 You're now known as TheWatcher[afk]
17:08
<@ToxicFrog>
(this also means you can write things like: $(sprintf('%s = %s', '$(tostring(key))', '$(tostring(value)'))
17:08
<@ToxicFrog>
(and even define new functions in $() blocks, although this gets ugly quite rapidly)
17:11
< Vornicus>
ah, that thing.
17:20
<@ToxicFrog>
And with that, I think, util.lua is ready for release.
17:26
<@ToxicFrog>
(well, apart from documentation)
17:34
< Vornicus>
interpolate would be better if you could name a format string.
17:35
<@ToxicFrog>
"name a format string"?
17:38
< Vornicus>
here's Python: "%(foo)06.2f" % {'foo': 5.375} --> 005.38
17:41
<@ToxicFrog>
("$(sprintf('%06.2f', foo))", { foo = 5.375 })
17:41
<@ToxicFrog>
But yes, some kind of extension to make that easier to write would be handy
17:41
< Vornicus>
well, that's not very pretty.
17:41
< Vornicus>
but it works.
17:44
<@ToxicFrog>
Yes, but it would be nicer if you could write: $(foo|06.2f)
17:44 * ToxicFrog implements this
17:45
< Vornicus>
ooh, I like that.
17:45
<@ToxicFrog>
Hmm. If I do it write, you could actually do something like: $(foo,bar|%s = %d)
17:45
< Vornicus>
...silliness.
17:45
< Vornicus>
I don't much like that.
17:45
<@ToxicFrog>
But is that really any better than $(foo) = $(bar|%d)?
17:45
<@ToxicFrog>
I think not.
17:46
<@ToxicFrog>
And it's harder to parse.
17:51
<@ToxicFrog>
Let's see... |[-#0+ ,I]*%d*%.?[%d$]*[qjzt]?[diouxXeEfFgGaAcsm]
17:51
<@ToxicFrog>
Is I think the ncessary regex.
17:55
<@ToxicFrog>
...except some things may return multiple values
17:58 * ToxicFrog flails
18:01
<@ToxicFrog>
Hmm. What do I do with multivalued returns?
18:01
<@ToxicFrog>
The previous implementation, I now realize, was just dropping everything but the first return value.
18:04 * ToxicFrog prods Vorn. Suggestions?
18:19 You're now known as TheWatcher
18:23
< Vornicus>
Hm.
18:23
< Vornicus>
What do you mean "what do you do with them?"
18:24
< Vornicus>
Python, everything has a __repr__ or __str__ method, which defines ways of converting objects to strings.
18:25
<@ToxicFrog>
Yeah, but I mean, say you have this: $(foo())
18:25
< Vornicus>
__repr__'s contract is approximately eval(repr(foo)) == foo; but a lot of objects don't do that.
18:25
<@ToxicFrog>
And foo() returns 1,2,3,4
18:25
<@ToxicFrog>
Not a list, but four seperate values
18:25
<@ToxicFrog>
Does it expand to "1", "1,2,3,4", "1 2 3 4", "1234" or something else entirely?
18:26
< Vornicus>
in Python that's technically a tuple (listoid) getting returned, and would print (1, 2, 3, 4)
18:26
<@ToxicFrog>
Yeah, Lua doesn't work like that.
18:26
<@ToxicFrog>
(if it returned { 1, 2, 3, 4 } the result would be "table: 0xXXXXXXXX" unless you applied a __tostring on it)
18:27 Syloq [Syloq@Admin.Nightstar.Net] has joined #code
18:27
< Vornicus>
Yeah - Python knows how to turn a list or dict into a string, which is why you don't see that.
18:27
<@ToxicFrog>
Well, raw tostring() is mostly for debugging.
18:28 Syloq is now known as Syloqs-AFH
18:28
<@ToxicFrog>
Anyways, my feeling is that (by default, anyways) 1,2,3,4 and { 1,2,3,4 } should not expand to the same string.
18:29
<@ToxicFrog>
But I'm at a loss as to what the former should actually expand to.
18:29
< Vornicus>
I would say, probably, (1, 2, 3, 4)
18:30
< Vornicus>
what happens if you say a = foo(), according to the definition given for foo?
18:32
<@ToxicFrog>
a == 1 and the other values are discarded.
18:32
< Vornicus>
Then do that.
18:32
<@ToxicFrog>
If you wanted to trap them all, you would do something like: a,b,c,d = foo()
18:33
<@ToxicFrog>
Ok, so, here's the revised spec.
18:34
<@ToxicFrog>
$(exp) expands to the value of expression, run through tostring(). If exp evaluates to multiple values, only the first is used.
18:34
<@ToxicFrog>
$(exp|fmt) expands to string.format(fmt, exp)
18:34
<@ToxicFrog>
And thus potentially uses all values from exp, depending on the contents of fmt.
18:37
< Vornicus>
okay, what's fmt got in it then?
18:39
<@ToxicFrog>
A sprintf()-style format string.
18:39
<@ToxicFrog>
Eg, to have foo() expand to "1 2 3 4": $(foo()|%d %d %d %d)
18:39
<@ToxicFrog>
To have it expand to "1" instead of "1.0": $(foo()|%d)
18:40
< Vornicus>
ok.
18:44
<@ToxicFrog>
(this also means that the above example becomes $(foo|%06.2f))
18:47
< Vornicus>
which isn't too bad.
18:47
< Vornicus>
I like that, actually.
19:19 Forj [~Forj@Nightstar-17168.ue.woosh.co.nz] has joined #code
19:45 Forj [~Forj@Nightstar-17168.ue.woosh.co.nz] has quit [Quit: Gone]
19:56 Forjadon [~Forjadon@Nightstar-17168.ue.woosh.co.nz] has joined #code
19:56 mode/#code [+o Forjadon] by ChanServ
20:02 Forjadon is now known as ChalcyLaptop
20:06 Forjadon [~Forjadon@Nightstar-17168.ue.woosh.co.nz] has joined #code
20:06 mode/#code [+o Forjadon] by ChanServ
20:06 ChalcyLaptop [~Forjadon@Nightstar-17168.ue.woosh.co.nz] has quit [Ping Timeout]
20:07 Forjadon is now known as ChalcyLaptop
20:10 ChalcyLaptop [~Forjadon@Nightstar-17168.ue.woosh.co.nz] has quit [Ping Timeout]
20:14 Forjadon [~Forjadon@Nightstar-17168.ue.woosh.co.nz] has joined #code
20:14 mode/#code [+o Forjadon] by ChanServ
20:15 Forjadon is now known as ChalcyLaptop
20:52
<@ToxicFrog>
Documentation is made of hate.
20:52 * ToxicFrog stabs himself in the face
21:14 You're now known as TheWatcher[T-2]
21:17 You're now known as TheWatcher[zZzZ]
21:27
<@gnolam>
But examples are made of sugar and spice and everything nice.
--- Log closed Wed Jul 25 00:00:08 2007
code logs -> 2007 -> Tue, 24 Jul 2007< code.20070723.log - code.20070725.log >