Skip to content

Instantly share code, notes, and snippets.

@nikic
Created December 22, 2011 15:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nikic/1510696 to your computer and use it in GitHub Desktop.
Save nikic/1510696 to your computer and use it in GitHub Desktop.
PECL discussion on SPL exceptions
(3:22:33 PM) johannes: hey ho helly\G
(3:22:33 PM) helly\G: Moin moin
(3:24:21 PM) chregu_ [~chregu@77-58-253-248.dclient.hispeed.ch] entered the room.
(3:25:56 PM) jpauli1: helly\G: helly ! :) morning ^^
(3:26:26 PM) helly\G: Jo
(3:28:41 PM) jpauli1: helly\G: sorry that the guy (forgot his name) who wants to review ext/SPL code seems not here ATM
(3:29:19 PM) nikic: jpauli1: Levi?
(3:29:30 PM) jpauli1: nikic: +1 :)
(3:29:39 PM) helly\G: Spl use or extend?
(3:29:40 PM) jpauli1: nikic: I'm not good at names remembering :p
(3:29:49 PM) jpauli1: helly\G: extend / re-code
(3:29:56 PM) helly\G: Ic
(3:29:59 PM) jpauli1: helly\G: lots of ideas :)
(3:30:05 PM) nikic: helly\G: Reimplement datastructures mainly ;)
(3:30:09 PM) helly\G: Ideas are always good
(3:30:10 PM) Ilia [~Adium@74.198.9.83] entered the room.
(3:31:19 PM) jpauli1: helly\G: :)
(3:31:35 PM) helly\G: Have him sent me a mail, maybe i find time looking at it
(3:32:05 PM) jpauli1: helly\G: ow you know, he mainly has questions about "Why that stuff has been designed this way?"
(3:32:26 PM) nikic: helly\G: btw, maybe you could answer some questions about exceptions now?
(3:32:28 PM) jpauli1: helly\G: As PHP is moving forward, ext/SPL would need some refactoring / changes :)
(3:32:48 PM) nikic: helly\G: We have some questions about the use of some exceptions ;)
(3:33:00 PM) helly\G: Shoot
(3:33:10 PM) jpauli1: nikic: I huess helly\G hasnt got the answer himself :D
(3:33:13 PM) jpauli1: g
(3:33:26 PM) nikic: well, let's start of generic :D
(3:33:38 PM) nikic: what is the distinction between RuntimeException and LogicException?
(3:33:48 PM) nikic: The descriptions say it's about compile and run time
(3:33:58 PM) nikic: But that does not make (much) sense in a PHP context
(3:34:12 PM) helly\G: Runtime means unforseen strangeness happened that the code does not want to deal with explicitly
(3:34:31 PM) nikic: From that destinction also most other questions follow like when one should use OutOfBoundsException and when OutOfRange
(3:34:46 PM) salathe: can <whoever> mail internals, lets talk about this in public :)
(3:35:18 PM) helly\G: Logic means who ever wrote the code was to lazy to protect against this nonsense from hapening or someone was too lazy to read the docs and sent crap to code and that code doesnt know what to do now
(3:35:19 PM) jpauli1: salathe: well why not start the conversation here and take helly\G inside it, as he's now here with us :)
(3:35:50 PM) helly\G: Change compile to design time if t hat is better
(3:36:18 PM) nikic: Hm, I'm not sure I understand this
(3:36:19 PM) helly\G: I wont mail about it but ask
(3:36:55 PM) salathe: nikic: this is what I told you (I think it was you) aaagggeeess ago
(3:37:02 PM) helly\G: Say you have a currency conversion function
(3:37:27 PM) nikic: salathe: It might be, but so many other people have told me so many other things about those exceptions in between ;)
(3:37:29 PM) helly\G: A negative value probably is a runtime exception based on some other code having some issue
(3:37:49 PM) nikic: If you ask five people What Runtime/Logic means you'll get at least twelve answers, you know
(3:37:59 PM) jpauli1: nikic: +1
(3:38:02 PM) salathe: nikic: meh, then they're just wrong :P
(3:38:10 PM) helly\G: If you however send a string with a number and a currency symbol you were just too lazy to read how to send the two currencies, hence logic error
(3:38:48 PM) helly\G: Does that make more sense?
(3:38:51 PM) nikic: helly\G: Oi, that's an interesting new interpretation @salathe I think you mentioned something else
(3:39:23 PM) salathe: I probably did
(3:39:48 PM) helly\G: Its not a new interpretation
(3:39:58 PM) nikic: helly\G: New to me ;)
(3:41:00 PM) nikic: helly\G: I asked a question on SO about that (http://stackoverflow.com/questions/8193798/outofrangeexception-vs-outofboundsexception) and got six answers on it (two deleted) and none of them said what you just said ^^
(3:41:00 PM) helly\G: I have toadmit i could have written more and better docs though
(3:41:57 PM) helly\G: Good for that ine person :-)
(3:42:33 PM) helly\G: One even, sorry' bad typing on tablet
(3:44:54 PM) nikic: helly\G: The "normal" interpretatoin of the difference seems to be whether the code can theoretically be right or is completely absurd. E.g. $calender->getMonth(15) doesn't make sense in any context (thus OutOfRange) but $array[7] would only be wrong for a SplFixedArray(5), but would be right for (8) (thus OutOfBounds)
(3:45:05 PM) Ilia left the room (quit: Leaving.).
(3:46:32 PM) helly\G: The first comments on that link above are ok
(3:46:38 PM) jpauli1: And those Logic/Runtime Exception are now widely used in frameworks and other PHP projects ...
(3:47:33 PM) helly\G: The name compile timewas chosen to indiate it is about errors that could or better should have been covered before the interpreter compiles the code as in at the time of writing the inherently flawed code
(3:48:17 PM) helly\G: So yes it is that distinction, completley wrong or just an incident at runtime that was unpredictable
(3:48:37 PM) helly\G: Often due to user inpu that wasnt checked enough
(3:48:46 PM) chregu_ left the room (quit: Quit: bye).
(3:49:00 PM) Tyrael: helly\G: I think there should be a more formal definition.
(3:49:08 PM) scoates left the room (quit: Quit: Bye!).
(3:49:27 PM) helly\G: Tyrael, just formalze my answer :-)
(3:49:36 PM) chregu left the room (quit: Quit: bye).
(3:49:42 PM) johannes: Pierre: http://downloads.php.net/johannes/php-5.3.9RC4.tar.bz2 (packaged on my box, not on snaps ...)
(3:49:42 PM) helly\G: Or do i have to do it better than i did so far?
(3:49:45 PM) mode (+o helly\G) by johannes
(3:50:12 PM) Tyrael: helly\G: if you could formalize, there could be no misunderstanding in the interpretation. :)
(3:50:38 PM) helly\G: Not against my intention sure
(3:50:51 PM) helly\G: I could still be completely misguided :-)
(3:51:24 PM) helly\G: Ok, what other qs while i still have time?
(3:52:17 PM) nikic: helly\G: Give me a sec
(3:52:29 PM) nikic: ah right
(3:52:37 PM) nikic: when should one use InvalidArgument and when Domain?
(3:52:51 PM) nikic: For methods the Domain basically are the arguments, or?
(3:52:54 PM) nikic: *is
(3:53:07 PM) helly\G: Yep
(3:53:21 PM) nikic: So when should one use them?
(3:53:24 PM) gooh_: Domain in math is the range of possible input that can generate a valid output. correct?
(3:53:39 PM) helly\G: Think of domain as mathemaical domain, as in a define range or set or class of values
(3:53:44 PM) jpauli1: :D
(3:53:49 PM) Tyrael: I liked the way where nikic was heading with his reasoning: the Range can be context dependant, but the Bounds aren't. so if your $a value can or can't be valid for your method depending on the state of your object, then it is OutOfRange
(3:53:50 PM) jpauli1: well done cross responding
(3:54:11 PM) Tyrael: if it can't make sense in any possible context for that object, then it is OutOfBonds
(3:54:22 PM) gooh_: Tyrael: like the EU?
(3:54:33 PM) helly\G: Sounds like a good distinction to me
(3:54:55 PM) nikic: Tyrael: I like that definition. Sounds good to helly\G?
(3:55:02 PM) nikic: oh, he just said that ^^
(3:56:02 PM) nikic: Okay, so when would one use RangeE?
(3:56:20 PM) nikic: (over OutOfBoundsE)
(3:56:35 PM) Tyrael: for example you implement the fixed array stuff using php classes. you pass your array size in the constructor
(3:56:35 PM) gooh_: its the opposite. range of possible outputs
(3:56:46 PM) nikic: yeah, but what could possible throw that?
(3:57:01 PM) Tyrael: if you pass an index greater than the size it was used for construct, that should be an outofrange
(3:57:42 PM) helly\G: If you define an enum as a number of consts
(3:58:18 PM) helly\G: Then pasing in another value means you did not check you code to be sane hence it is a compile time error
(3:58:46 PM) helly\G: As in you should make sure that the caler uses the defined values only
(3:59:43 PM) nikic: helly\G: Was that about RangeE vs OutOfBoundsE?
(3:59:52 PM) helly\G: If later you are crazy and drop a defines values then youd also throw a compile time error rather thana ru time one to ndicate that the callers still using the old value didnt bither to adaot their code to the new api
(4:00:13 PM) helly\G: Say percentage
(4:00:32 PM) helly\G: The range might be 0...1 or 0..100
(4:00:58 PM) helly\G: A wring value can be both, depends
(4:01:26 PM) helly\G: Using a 0.7 when only concrete values are allowed than thats a domain error
(4:02:49 PM) helly\G: Nw if the value was a geerated value or a value taken from a config file id argue its compile time unless its a user maintained edited config
(4:03:26 PM) nikic: Sounds very complicated
(4:03:42 PM) helly\G: Not complicated
(4:03:43 PM) nikic: If you need to throw different exceptions based on where the data comes from ^^
(4:03:47 PM) helly\G: Its subtle
(4:04:13 PM) helly\G: Not where it cmes from, based on how stuff plays together
(4:04:37 PM) helly\G: Inside a library all internal exceptions should be compile time exceptins
(4:04:54 PM) chregu [~chregu@77-58-253-248.dclient.hispeed.ch] entered the room.
(4:04:55 PM) helly\G: All exceptions from public calls shuld probably be runtime
(4:06:54 PM) nikic: okay
(4:07:10 PM) nikic: so should we interpolate what Tyrael said ("the Range can be context dependant, but the Bounds aren't. so if your $a value can or can't be valid for your method depending on the state of your object, then it is OutOfRange") into the docs?
(4:08:42 PM) scoates [~sean@modemcable087.149-80-70.mc.videotron.ca] entered the room.
(4:09:37 PM) g0pz [~gopalv@122.179.83.169] entered the room.
(4:10:04 PM) jpauli1: g0pz: back ? :)
(4:10:35 PM) helly\G: If one is context dependant then shuldnt that be runtime since the context is only clear at runtime?
(4:11:46 PM) g0pz: jpauli1: just diving out of office and back home :)
(4:11:57 PM) jpauli1: g0pz: k
(4:12:16 PM) nikic: helly\G: Ah, I think that Tyrael swapped Range and Bounds ;)
(4:12:28 PM) jpauli1: g0pz: so hidef is about reading params in .INI and storing them in pmalloc()ed memory for them to be quickly accessed right ?
(4:14:00 PM) g0pz: yup, stuff like localization tables
(4:14:13 PM) g0pz: where you need the whole array in mem, but only need to pull one item out
(4:14:30 PM) g0pz: with a bit of "ease of use" code in FrozenArray
(4:14:39 PM) jpauli1: g0pz: ok, just a key-value store, but a local one ?
(4:14:44 PM) mode (+o g0pz) by Felipe
(4:14:57 PM) g0pz: the .ini part does define() code
(4:15:03 PM) mode (+oooo dmitry chregu auroraeo1 lsmith) by Felipe
(4:15:17 PM) jpauli1: g0pz: yes ok, cool, its like constants
(4:15:18 PM) g0pz: the latest patch of hidef.per_request_ini was to handle different app secrets for the same codebase
(4:15:34 PM) jpauli1: g0pz: with overwrite ?
(4:15:40 PM) g0pz: so the code in /common can be in 3 vhosts, each with their secret key in an .ini
(4:15:43 PM) g0pz: no, no overwrite
(4:15:44 PM) jpauli1: g0pz: overwrite MINIT()ed values ?
(4:19:21 PM) plutoniix [~plutoniix@125.25.20.116.adsl.dynamic.totbb.net] entered the room.
(4:19:48 PM) g0pz: this lets me put code once in /var/.../ and vhost it to "xyz.foo.com" with /etc/vhosted/xyz.ini and xyz2 with /xyz2.ini
(4:19:48 PM) RoUS [~coar@nat-pool-rdu.redhat.com] entered the room.
(4:19:49 PM) g0pz: they both now accept cookies with different signatures (md5(cookie + secret) == sig)
(4:19:49 PM) g0pz: jpauli1: I wanted to do overwrites, but then I declare stuff with CT_SUBST, which replaces it in the bytecode (apc cache)
(4:19:50 PM) g0pz: so I have to recompile everytime I change a constant :)
(4:20:35 PM) Tyrael: nikic: where did I swap it?
(4:21:39 PM) nikic: Tyrael: You said "he Range can be context dependant, but the Bounds aren't" But imho it's the other way around. Range(Logic) is for context indep and Bounds(Runtime) is for context dep
(4:22:11 PM) jpauli1: g0pz: ok
(4:24:43 PM) Tyrael: ok, then we see this from a different POV then. I separated those based on that there could be a case, where your Logic is the same, but depending on the runtime context (how did you initialize your class) the same value can be either wrong or right.
(4:25:49 PM) Tyrael: if it is completelly off even without knowing the context, then it is an OutOfBonds, if it can only judged knowing the context then it is an OutOfRange
(4:25:58 PM) Tyrael: maybe it's just me who see that way
(4:26:42 PM) nikic: Tyrael: But why? OutOfBounds is a Runtime exception, why wouldn't that be the context dependent one?
(4:27:44 PM) Tyrael: I didn't restricted myself to the documentation when I did my interpretation. :P
(4:28:06 PM) beberlei [~chatzilla@ip-178-200-247-30.unitymediagroup.de] entered the room.
(4:28:08 PM) nikic: ?
(4:28:14 PM) Tyrael: checking that now, yeah, my version and the documentation is swapped.
(4:28:25 PM) nikic: ^^
(4:29:03 PM) Tyrael: somehow I felt natural that the Ouf of bounds is way more off than out of range
(4:29:07 PM) Tyrael: like 1,2,banana
(4:30:52 PM) nikic: I'll update docs as soon as I find time
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment