« first day (4538 days earlier)      last day (392 days later) » 

9:41 AM
@Trowski this symbol comes from raphf, so you need raphf to be loaded before pq
/me should have noticed this is a old question...
 
 
3 hours later…
12:24 PM
@OlleHärstedt my gut is that a data object should never need to depend on any services, even a logger, because there shouldn't be anything interesting to log; you might log a problem when hydrating from the database, but that would happen in a factory/repository/query service, and result in either an exception or a valid data object
the only thing I can think of that would be hard to log outside the data object is some kind of deprecated access pattern that's hard to detect with a static analyser
 
12:59 PM
@IMSoP Well there might be more complex object that depend on loggers, not just simple data objects. Right?
But it's getting close to this design principle: A class should not have both internal state and shared (injected) resources. In fact, maybe they should not even both be called "classes"?
But it won't fly because business logic often needs to be logged/traced in different ways.
And obviously you don't want to pass around loggers manually. Or?
 
business logic should be in "service" type objects - they have properties storing other services they interact with, and some configuration fed to them on creation
they should be responsible for creating, reading, and maybe mutating data objects; and those actions might have conditions that lead to logging
but the data objects themselves should just be data - they don't do anything
if String was a class, you wouldn't expect it to need a logger; so nor should an Address class which composes a set of strings, and nor should a User class which composes an Address with some other bits
that's what I see as the goal to aim for, anyway
 
@IMSoP Are you saying objects never have both data and logic? :)
 
ideally, yes
 
Well. Good bye OOP.
 
for some definition of "logic"
 
1:09 PM
Which is fine I guess, it's just not common in PHP.
 
OOP is still useful for, say, deriving different representations of the underlying data
 
Also messes up encapsulation since PHP lack package private access.
If you have order or invoice classes, and they do economical calc, it's sometimes nice to log stuff there.
 
I'd have to see an example, but it smells of too many responsibilities pushed into the Invoice to me
 
Not lots of code is perfect out there.
But anyway
 
4 mins ago, by IMSoP
that's what I see as the goal to aim for, anyway
I didn't say code is that way; just thinking about what architectures we should be aiming for
 
1:13 PM
I don't know why it irks me so much, but having stuff like new Invoice($amount, $logger); bothers me. As an example.
 
@RemiCollet Yeah, I quickly realized ordering was the problem once I noticed the function was in raphf. The docker install helper generated ini files which loaded them out of order.
 
@OlleHärstedt I agree it looks wrong, because the Invoice should not need a logger
the code that needs a logger should be somewhere else
 
@IMSoP I'm operating under the OOP assumption still, that logic and data goes together "mostly".
Also you have to consider how code evolves.
 
classes should have repsonsibilities
the Invoice class is reponsible for representing an Invoice, not for "doing anything related to invoicing that the application needs"
 
I never saw a single definition of what a "responsibility" is.
 
1:15 PM
so "create a Payment from an Invoice" is not the responsibility of the Invoice or Payment classes, but a service which takes one and spits out the other
and that's the code where a Logger would most likely be used
again, I'm not saying it's easy, I'm saying that's the goal, and moving closer to that goal moves you away from wanting new Invoice($amount, $logger)
 
Yeah, but you move away from oop with such a def, since "logic" becomes one responsibility and "data" another. :)
I don't think that's uncontroversial.
 
The encapsulation approach can be cleaner, but the more procedural / functional approach is usually quicker and has less surface.
 
But I get what you mean, I also do fp coding, and rarely use classes in that environment.
@MarkR Surface?
 
@OlleHärstedt The encapsulated object could end up with a lot more functionally exposed through it than individual services that take a model / data as an argument.
 
Maybe, but you need a bunch of getters on the data object then. Again, due to PHP not having package private.
 
1:22 PM
In our newer code we tend to define all the data (models) and services and then inject those services alongside a model to form an object-orientated handler where the services are already attached.
 
Edited, meant data and services, not data in services
 
Ok, but if you DON'T do that, maybe traits can be used for setter-injection of shared resources :d
Then at least you don't mix values and resources in the constructor like a mad person.
Someone on reddit hinted at effekt-lang.org/quickstart.html to see a language-level solution of this problem.
 
1:37 PM
@OlleHärstedt that is almost certainly a case of:
2 days ago, by Danack
Though also...there's a strong chance you just need to use more powerful factory types.
 
What's a factory type? Factory class?
 
class InvoiceFactory {

	function __construct(private Injector $injector) {
	}

    function createInvoice($amount) {

        // You could move this line into the constructor, to
        // limit the potential for having run-time config errors
        $logger = $this->injector->make(Logger::class);

        return new Invoice($amount, $logger);
    }
}
@OlleHärstedt yes.
 
What you need there is a module-private invoice constructor tho. :)
Or namespace-private or whatever
 
Not so much.....once you've created that factory, it becomes easier to use it, than to create objects by hand....and people tend to follow the easiest path. btw, I have a suspicion that the problem you're seeing is not a universal problem. aka it might be slightly specific to your code base, and we're slightly talking past each other.
 
@Danack No no, both you and Mark have interesting approaches I think.
 
1:51 PM
I don't think I have any problems with mixing up data and services aspects in a single class, possibly due to very rarely using mutable classes, but I have been thinking about making a CI tool that prevents layers talking to the 'wrong layers'. e.g. imagine you have these layers in an app:
* bootstrap
* routing
* controller/command
* service (aka a generic 'does stuff' layer)
* repository (aka data layer that uses app level names)
* http/DB (aka data layer that uses strings for names)
There might be value in preventing the controller layer from being able to depend directly on PDO, because that is probably going to be a hard to test bit of code, and also potentially hard to reason about.
 
No "shared resources" layer?
Db, logging, etc
@Danack I'd be interested in such a tool IF it could also enforce purity at certain layers. :D Then you have functional core, imperative shell enforced in CI.
 
'No "shared resources" layer?' - all of that wiring up is taken care of by the Auryn injector...tbh, I think I would need to take a look at your code to even precisely understand why you think db/logging would be a 'layer', and not just 'code'.
 
@OlleHärstedt I think there's different definitions (or degrees?) of OOP; an Invoice can still have behaviour, just not the kind of complex behaviour that would invite side effects like logging
 
@IMSoP Like validation, enforce invariants? Sure.
 
yeah; and indicate problems to the caller (e.g. throw an exception) with the caller then responsible for what the effect of that problem is (e.g. log a message with useful context)
so $gbpInvoice->addItem($usdProduct) might be an error, but it's not the Invoice's responsibility to log that error
 
2:05 PM
Depends on how precise trace you need in production.
 
generally you want to know the cause of the error, i.e. why did we try to add a product of the wrong currency
which line of Invoice.php detected that is less relevant
in that example, at least; again, hard to know what complex examples look like without a deep dive into an application
 
Did you ever debug an economical bug in production? :)
 
@Danack I'm sure I saw such a tool once, but can no longer remember what it's called; may have been a ruleset for PhpStan or something
@OlleHärstedt hard to answer that in the abstract; I suspect I'm just not thinking of the same kinds of operation as you
 
2:25 PM
Sigh. Anyone knows Joomla by any chance...?
JPATH_ROOT is set to "[ROOT]" for some reason.
 
@OlleHärstedt Danack's approach is very similar to mine, my comments were more aimed at mutation and root relationships. I would definitely use a factory to convert say a Cart into an Invoice as it might need to pull in data from a bunch of things, taxes, contact info etc.
But let's say I had a Model_Cart that was wrapped by encapsulation, I may very well have an addProduct method on it
 
@Danack "dependency analysis" seems to be the magic phrase to search for; dephpend.com and mamuz.github.io/PhpDependencyAnalysis look interesting, but neither seems directly optimised for CI enforcement of an existing structure
 
ta
 
this looks closer to what I think you meant, but hasn't had much work: github.com/paglliac/php-dependency-analysis
oh, I think this is the one I was thinking of: github.com/qossmic/deptrac
 
I recently tried codescene.io which had some automatic module detection
 
2:40 PM
cool, will add that to my list
this also looks interesting: github.com/carlosas/phpat
going to have to try some of these on a few of our repos, see how badly they explode
 
3:38 PM
I can't create Wiki pages - I need to create wiki pages for the php.net redesign, as all the documentation and planning stuff is on my machine here, when having meetings with team members.

I wanna get it all onto the wiki page.

Who can give me the CREATE karma, please?

If it matters, all changes will be located here, in web: https://wiki.php.net/web
Are we still using EFnet btw? or have we replaced it with room 11? lemme know for future reference, cheers
 
3:49 PM
@Derick is this something you can sort for me?
 
 
3 hours later…
6:35 PM
question, since we have typed properties that can also by readonly - meaning there are guards on write operations wouldn't it be possible to introduce typed arrays of any type without much of a hassle? Talking about what KrakJoe proposed long time ago with int[], string[] or any DateTime[] type ?
 
I think the problem is the efficiency of the check itself - if you have an array of 200 elements, every int[] check has to effectively do 200 is_int calls
the only way I can think it would be practical is if you had a cache saying "this zval has been checked for compliance with an int[] check, and not modified since"
or am I misunderstanding you?
 
That's why you do it when adding it to the array.
 
oh, so you mean having int[] as the zval's type, essentially?
so more like a limited form of generics
 
6:55 PM
yeah, "collections"
 
I guess some existing array functions would need to be made aware of the new types, e.g. if $foo is of type int[], then sort($foo) is also of type int[]
and then something like (int[])$plainArray to cast existing values
 
7:29 PM
@IMSoP yes this is what I was thinking, sort of cache which says the oval was already checked
Would it be possible as a small RFC without need for bloated implementation in C. I mean some has to be but meaning it wouldn't require drastic and complex changes in engine, right?
Java has generics but they also introduced these simple collections type as well and they exist simultaneously
 
7:46 PM
heya o/
 
Hi o\
 
8:13 PM
Hey @PeeHaa :-)
Wishing everyone a happy Monday, and a productive week ahead! :-)
 
Found the old RFC wiki.php.net/rfc/arrayof
 
 
3 hours later…
11:10 PM
> Because of your contributions on GitHub, two-factor authentication will be required for your account starting May 4, 2023.
So my GitHub account officially is too big to fail now?
 
11:27 PM
@TimWolla reply back, asking how much they will compensate you for this inconvenience?
er, also, I guess I will too.
> Cursed Treasure. A problem such that whoever solves it will be punished, or suffer severe negative consequences.
 
11:48 PM
I got an email too.
 
If anyone does have a contact a github, there is a useful conversation to be had, probably: twitter.com/MrDanack/status/1637960471633440768
 
@Danack I had 2fa already enabled anyway, because I personally consider that a good thing (I enable it for every reasonably relevant account of mine). Several of the GitHub organizations I'm part of already require 2fa as well, so nothing changes for me.
 
@TimWolla So do I, because it's a sensible thing to do. But that is very far from the point.
 

« first day (4538 days earlier)      last day (392 days later) »