logs archiveIRC Archive / Freenode / #php / 2015 / October / 13 / 1
profsimm
I need feedback on API design for a library I'm working on. Thoughts? --> http://pastie.org/10477387
edwardly
profsimm, getLog being an attribute instead of a method is confusing
profsimm
edwardly: whoops, the one confused am I :P I forgot ()
edwardly: it's a method :D
edwardly: same for hasErrors() :P ad damn
Fixed: http://pastie.org/10477392
Literphor
profsimm, You're creating a library that's going to be used by other developers?
profsimm
Literphor: hopefully. I'll FOSS it.
Literphor: I already have a version of it internally, and it's really really really useful.
And I can't wait to share it, but before I do I want to make sure I fix some things I doubt about
Like this.
gcds
How to call a namespaced function with call_user_function?
call_user_func*
profsimm
gcds: you can have "\" in your string name
gcds
profsimm: does not really work :D
profsimm
gcds: it really should, pastebin reproduce code if you have a problem.
         

Literphor
profsimm, I don't have any experience developing libraries used by other developers, but IMHO you want to throw errors and allow the developer to handle them whenever possible
profsimm
Literphor: I'm just asking for feedback, about you as a potential user, nothing more. Thanks for your feedback :)
gcds
profsimm: sorry my bad I forgot to add that function to autolaoder (facepalm) :D
Literphor
profsimm, In my experience libraries handling and attempting to resolve their own errors has caused me unnecessary headache. It shuld be straight forward about what your API expects and should blow up consistently when somethings wrong. Side affects are an issue and a library shouldn't modify my input so it can "work out exceptional cases"
profsimm
Literphor: I think the problem is more about how to pass errors. It works the same in all ways. Takes input, returns output, on problem, adds errors to the log.
Literphor
profsimm, There's a potential issue. Where is it logging and what is it logging? Do I have any control over that logging? As a potential user of your library that seems unnecessary...if I want those errors to be logged I can do that myself
profsimm
Literphor: I think the name "log" is confusing here I guess.
Literphor: this is just an EventList, a list of Event, which can be Warning or Error
Literphor: say when you validate an input form, you get an Error for every bad field.
Literphor: the log is just in memory, although Log implementation may also log to a file or DB
Literphor: I can rename it to $eventList I guess
Literphor
profsimm, I understand. Are you writing an error handling library then? If not then I stand by that you should allow the user to do their error handling... I don't want to have to check a list that's specific to your library, not when I can do my own error handling (if you allow me)
profsimm
Literphor: how would you refactor one of these examples so I can still pass a list of errors (say for every field) back to you?
Literphor: I'd gladly drop EventList/Log if there is a simpler solution
Literphor
profsimm, I wouldn't manage a list of errors. The simple solution is to just allow the exceptions to be thrown and handled by the user
profsimm
Literphor: that's a problem because let's take this example: list($validForm, $errorList) = $registerUserTransform->apply($_POST);
Literphor: how would the object report which fields were bad and why?
Literphor: an exception has a single message and code. That's all.
To improve my example a bit:
Literphor: that's a problem because let's take this example: list($registerUserForm, $errorList) = $registerUserFormTransform->apply($_POST);
Literphor
profsimm, Well assuming you're iterating over $_POST and validating the fields, if I come across an invalid field I would do something like "throw new Exception('Invalid username, must be 8-16 characters long')"
Chunk2
Is it worth trying to implement any async loading in PHP?
dafr
Chunk2 async in terms of?
Chunk2
Like, database queries, third party server access etc
profsimm
Literphor: this would mean I can't report errors on multiple fields, which is common with forms.
dafr
Chunk2 facebook already did this for you
Chunk2
There are some libraries that purport to do it, at least for http operations
profsimm
Chunk2: if you have performance issues, yes.
dafr
Chunk2 and there are async libraries for all kind of stuff (http, mysql, etc.)
         

Literphor
profsimm, Of course you can. You iterate over $_POST in its entirety and throw the exception after I was done validating
profsimm
Chunk2: for HTTP in particular it's useful if you need 2+ requests done at once.
Chunk2
dafr. profsimm: so it works well enough for production then?
that's good to know
profsimm
Literphor: how would you map a string $message from the exception to every field back in the form...
dafr
Chunk2 facebook implemented async operations in "hack"..
if you want to send multiple http requests at once, any good http library will do the trick (like guzzle)
profsimm
Chunk2: depends on the library but PHP supports sending multiple requests and then "selecting" them all at once when done, so this is one way libraries do it. It works fine.
Literphor
profsimm, All the fields have a key?
profsimm
Chunk2: don't forget to set reasonable timeouts!
Literphor: yes but where will you pass that key in an Exception?
Chunk2
I'm from a node.js background
Literphor
profsimm, You create the exception...you can either encapsulate the data or you can include it in the message you're making...
sdfdsf55sss
Do one have to close pdo prepared statements before one launches a new one(with the data from the old one)?
Chunk2
it's kind of tortuous getting my head around the way things are done imperatively
if that's even the right word for this
profsimm
Literphor: well in the last example I encapsulate it: ExceptionWithLog $e ---> $e->getLog()->getErrors();
dafr
Chunk2 http://guzzle3.readthedocs.org/http-client/client.html#sending-requests-in-parallel
Literphor
profsimm, Something like "throw new ProfSimmInvalidationException("These fields are invalid!", $myfields);"
sdfdsf55sss
Here's my code: http://pastebin.com/MuHRR20m Is it bad?
Literphor
profsimm, You can manage an error list if you like, I just don't think itsw a good idea
profsimm
Literphor: thanks, I'll think about it!
Literphor
profsimm, You're example can be shortened to just "list($output, $log) = $transform->apply($input);" assuming $transform->apply throws an exception when an error's encoutered. That's less coding for you (no error handling) and you give me the flexibility to handle my errors how I see fit
s/You're/your
profsimm
Literphor: that's my first example verbatim :)
dafr
sdfdsf55sss you could get rid of the select statement with PDOStatement::rowCount()
profsimm
Literphor: oh wait, you want it to throw.
dafr
sdfdsf55sss everything else looks "okay"
profsimm
Literphor: so that's the last example verbatim then :D
sdfdsf55sss
dafr, ok. i thought maybe i had to close the old statement befor ei made a new one, but i guess you don't have to do that with pdo?
dafr
that's not necessary
sdfdsf55sss
coolio
makes things easier :)
Literphor
profsimm, I assumed that was YOUR code...if that's suppose to be from the perspective of the user making a try/catch block then yes I agree that's a better approach
profsimm
Literphor: ah damn me :)
Literphor: yup it's user PoV
sdfdsf55sss
I don't understand how i can get rid of my select by counting how many rows were affected by it though?
Literphor
profsimm, Then then only other thing I have to say is that ExceptionWithLog breaks the Linksov-substitution principle, you want to avoid encapsulating a log in tht way
profsimm
Literphor: it doesn't break it though :) It's still a valid exception.
Literphor
profsimm, So it has detailed message? I'm not forced to use getLog()->getErrors() in order to what exceptions are encoutered?
*in order to see what
profsimm
Literphor: the message is generated from the events, and yeah, it's kind of a very long string describing every error event.
Literphor: it's useful for debugging.
Literphor
profsimm, Betteer for it to be a long string than for it to be incomplete
profsimm
Sure!
Literphor
Kudos then :p
profsimm
^_^
xreal
OH nooooooo
Noooo.
'Y-m-d H:m' - I tried the WHOLE day to figure out, why minute is wrong :)
Slartibart
That's a classic :-]
Chunk2
I just realized something... does PHP-CLI need permission to write to php-errors.log in order for it to work?
Like, is the error logging handled by some underlying messaging mechanism that has permissions or do I need to make it accessible to the user who's running the cli script?
This might be a linuxy question
AcidReign
yes it needs write perms on the file
« prev 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 next »