@kelunik Yeah....I'm giving a talk on DI next month.....and I think the final point I'm going to try to make is that to do DI properly, you need more than 1 layer of dispatch in an application, as it is not possible for all information to be known ahead of time to setup DI, for say the view layer. That doesn't apply to APIs as for them it is possible to know everything ahead of time.
But for a webpage, where the template/view to be displayed can't be determined until the page controller has run, you need to have another layer (or dispatch) after the controller has run, where the info for the template can be setup. You said you only need to do DI once - I was going to pick an argument ask how you were getting the info into the views.
But as you avoid that problem by serving an API, it's probably not something you've had to address.
Just as an example. Say you have a front-end app, that makes an http api call to a backend server. The backend server will have it's own config setup + dispatch layer. If you wanted to get rid of the http slowness, by just putting the two apps into one, you would almost certainly still need the 2nd level of config setup + dispatch, at the place in the program where the API call was made before...
though I'm not 100% convinced that is totally correct...
How do you deal with a function that will end up requiring about 10 parameters, like a function call that retrieves results from the db with filters, date_start, date_end, sent, offline, etc...
@Danack To be honest: templates and views are things that are not properly implemented in my Aerys app, because there are just three or four http handlers and it's something that I have to implement later when the Aerys API stabilized.
@kelunik If it's just a plain function call then yes, but if it takes the parameters, sets up some DI config based on those parameters, then it would need the 2nd level DI stuff.
@Danack I'd say that's accurate. You can't make decisions based on information you don't know yet. This isn't really about the API though, it's simply about requiring some application logic to execute before you can complete your setup, which is pretty much standard in any application if we're really honest. That said, I can't see this affecting DI, at that second layer you'd use factories that were injected during the bootstrap.
The reason is: You don't want to hit your disk for any request. You want to cache those things directly and it's possible, because Aerys is a long running script.
@Fabor I'd rather VO it, and I think that's probably because it plays nicer with static analysis, but yeh you probably want some kind of complex structure to describe related parameters like that
@DaveRandom Yeah....but factories are boring.......and it's possible to need to have a lot of them. e.g. if a controller might want to display one of 4 views as a result of the code in the controller, then having to pass in an extra 4 parameters (1 factory for each of the possible views) would be a bit annoying....
not sure that's a good argument for/against anything :-P
@Danack I don't see any problem with having a generic ViewFactory with multiple create* methods, I do this all the time and have never heard a good argument against it.
@DaveRandom Presumably the views could/will have different dependencies, that the controller shouldn't be aware of. How do you get those dependencies into the view, without having a separate factory for each view?
@Danack A lot of those will be shared, but yeh I suppose it could get messy. As someone who doesn't really do DIC I guess I never really thought about it.
I've always enjoyed burying my head in the sand. Sand is dark and soft and people can't tell the difference between you ignoring a problem and just catching up on a bit of sleep.
^ I want to avoid that exception, because it would be user-triggerable, but still access the error message, if it's there. Does anyone have a suggestion?
@FlorianMargaine Malformed or bad user input shouldn't result in exceptions IMO. But there may be no there good way in that case, because I can't validate the $code before.
can one in some way call a method from another class, and set the "this" object in PHP? like JS apply /call methods. so from method A::foo we want to call method B::bar but $this should still be the A object.
@PeeHaa If GitHub would suddenly add a Deny Access button, an error would be a normal condition. I think Facebook has something like this, so you can ask for different permissions and you can allow only some of the asked ones.
That would actually not give you a code but result in a error being present in the URL.
@PeeHaa There will be one later, of course. Well, the only thing that would change if not using an exception would be: there's no exception object instantiated.
> The system service "Memory Paging Management Service" could not be started because there was not enough system memory available to satisfy the requested resources. Try increasing the size of the system page file.
@LeviMorrison you were right, even with maniacally optimized php code, seems that avltree is slower than php's arrays. with the possible exception of unshift (but only on big lists) :( would be great to have a bst implemented in spl. can you do that? :D
@kelunik I think we've had this conversation before - and that I disagree with the premise that user input should never throw exceptions....But for this case, the choice is between an exception, or having a some sort of validator that either redirects the request to an error page, or continues to process the request if it's valid. And if there's no sensible place to put the validator, then exceptions aren't the worst thing to abuse...
Anyway @Jimbo, been working on github.com/J7mbo/twitter-api-php/compare/… and have been trying to work out a couple of things. Firstly, is there any good reason to prohibit adding query string parameters to a POST request? It's a valid thing to do in terms of HTTP, do Twitter disallow/definitely not use it?
Also, I suspect one of the examples in your readme makes no sense
@ThW Not sure how that changes the perception that ugly code is a good thing. Code, while meant to be run by machines, is entirely consumed by humans. Humans like pretty things.
@Sherif "pretty" is a matter of taste, I don't think it is pretty. But I try to find more objective reasons for code formatting - and my main goal is to write source that is easy to maintain.
@ThW Of course it is. Though there are objective reasons for using whitespace to align columns and rows of collective things. There have been many studies conducted on the subjective matter that proves objectively that humans are productive when they can process large amounts of data in chunks. It's the same reason it's easier for you to memorize a phone number in the format of 555-123-4567 more easily than 5551234567.
One things just become one big blur, your mind tends to ignore them.
@LeviMorrison Really? In a world where IDEs can do all of this for you automatically you believe that your pain-point in writing code is having to do deal with indentation and alignment? I find that very hard to swallow.
@Sherif I'm not saying it is "my pain-point". I am saying that it is more painful for everyone whose IDE is not configured or doesn't actually have an IDE.
That's all.
Also, when the key and the value get far away it gets harder to understand.
@PeeHaa Normalizing the language we're working with actually lends itself to emphasizing the validity of the statement more than deviating from it. It just means we're all already accustomed to a relateable syntax and so what subject matter is left is moot by comparison.
@LeviMorrison I can understand that it may be mundane and in that sense painful. Though I still can't see that as a good excuse for choosing to make an already painful situation even more painful by having to stare at ugly code all day.
@LeviMorrison I have, actually. It makes it easier to digest groups of information more quickly. The human brain is used to picking up on patterns more quickly than serial information. If you align the rows and columns it effectively makes you more productive and less prone to PEBKACs in the long run.
@PeeHaa Actually, I do find that very useful especially when you set the IDE to show you tabs vs. space discrepancy in indentation. Helps me catch wonky misalignment across large code bases eventually.
but tbh I imagine the expectation of most people using set_exception_handler would be that it would handle all possible exceptions, and introducing new exceptions/new exception types would simply result in them being sent to the exception handler as-is, i.e. the current proposed behaviour is corrent, even if naming is not-awesome...
@salathe Yes, sorry, $baseType would be better, where $baseType must inherit (or be) Throwable
Yeh, I'm just not sure how it would work in terms of precedence, or at least how you would avoid an O(scary) op to determine the correct handler for a specific scenario. And while there's an argument that this matters less for this scenario, since something already went wrong because there's an uncaught exception, it's still not obvious to me how one would implement the logic
Will think about it some more
@Trowski I presume that extending Throwable is prohibited, as well as implementing it directly?
I quickly tested, and BaseException did trigger the function set by set_exception_handler(), and of course then so do uncaught Errors in my implementation. set_exception_handler(callable $handler, $base = 'Throwable') seems reasonable if someone can figure out how to implement it.
@salathe I agree, though I think the new hierarchy will be easier to explain than the old one.
You can now catch fatal errors, but not all fatal errors, as they derive from the new Error class. They're basically exceptions, but can't be caught with catch(Exception) but can be with set_exception_handler(). To catch() them, catch the new Error class or to also catch Exceptions, catch the Throwable class. By the way, you can't throw everything that extends Throwable, because userland code cannot implement Throwable or extend Error. ... :/
@salathe If you write it in a confusing way, yes, that is horrible. Also, replace Error with EngineException and Throwable with BaseException, it's not better, it's much worse.
@salathe So catch (Exception $e) won't catch this thing called EngineException, you have to add another catch block catch (EngineException $e), even though the name EngineException looks like it extends Exception, it really doesn't.
I'd rather see two kinds of exceptions, that are basically the same but don't overlap ("core vs other" exceptions) than two kinds of errors that are completely and utterly unrelated in every way.
@Trowski At least that keeps the name Exception in everything, which is a win in my book. So the hierarchy isn't based on Exception, I can live with that.
@salathe I believe the "simple" rule is that anything which leaves the engine in a potentially unstable state is a fatal error. As a general rule this is things that could not be mitigated in userland no matter what you do.
@LeviMorrison I spent a lot of time on GitHub looking for collisions. There were very few, and mostly from projects that looked unmaintained. Anything else used namespaces.
@salathe maybe you aren't "particularly strongly against naming something ____Error that's really an exception in disguise." … others may feel stronger about it ;-)
notes that we're apparently allowed half-a-dozen more RFCs on throwable hierarchy, but he apparently has no chance of getting a simple new notice merged =(
@LeviMorrison Sure, just providing what you may find to be objectively helpful information. After all arming yourself with more knowledge can never hurt ;)
@DaveRandom Just add the getters - there's only a few and it makes the object API more concise... don't need getters for all the things
user895378
@VeeeneX I don't really understand your question ... perhaps you could rephrase it?
user895378
@kelunik lol well ... I didn't design it with obsessive performance in mind ... but I also always consider the performance impact of individual coding decisions as a matter of general principle so hopefully the library isn't excessively slow.
@Jimbo Yeh that was making some stuff available via public (some read-only) properties, I'm going to redo those as getter/setter methods and throw the magic out. It needs to exist in the BC adapter, but not anywhere else. For now I'm going to keep the only-URL-or-body params limitation in place for now, but I suspect it's pointless and can be lifted at some stage down the line. Would you be happy, in principle, to use that as a base for v2 though?
Also @Jimbo I presume the POST example in the readme is wrong, as I think you need to "set the post fields" before you "build the oauth"?