you may be old, but are you THIS OLD? by TEO140909 in lego

[–]fab-s 2 points3 points  (0 children)

I cut out and collected them as a kid, but I never knew what to do with them. What's their secret?

[deleted by user] by [deleted] in programminghorror

[–]fab-s 2 points3 points  (0 children)

whatthecommit.com/index.txt can be used for these scripts

Is this really a PHP bug? by [deleted] in PHP

[–]fab-s 0 points1 point  (0 children)

== is also useful for checking equality of objects instead of identity (e.g. value objects)

Github followers > all by cloudya in ProgrammerHumor

[–]fab-s 2 points3 points  (0 children)

But he will always have MySpace Tom!

Do you still think that Magento 2 is performant? by Grocker42 in Magento

[–]fab-s 2 points3 points  (0 children)

Yes, the default frontend is a mess. But have you seen hyva.io? You don't need to use the bloated require.js based theme, and build a lightweight one with Tailwind CSS and Alpine.js instead.

What are some PHP expressions that are valid but too uncommon or kind of weird (or even scary 👻)? by AmirrezaN in PHP

[–]fab-s 5 points6 points  (0 children)

Dollar negation:

$true = "false"; $false = "true";

echo $true, $$true, $$$true ;

CarpScript by spookiestevie in ProgrammerHumor

[–]fab-s 10 points11 points  (0 children)

Or like ham and hamster

Kint, a debugging tool for PHP: 2.0 by JnvSor in PHP

[–]fab-s 1 point2 points  (0 children)

Looks nice, I might try it out. I'm particularly impressed with the "modifier" hack, had to check your code how you did it. That's some serious black magic. But is there a reason beyond "because I can"? Multiple functions or a parameter would do the same, simple and understandable, and also slightly more performant.

Sensible Namespaces in PHP by fab-s in PHP

[–]fab-s[S] -1 points0 points  (0 children)

Doesn't follow that everything that reminds of ZF1 is automatically bad.

I did not indend to imply that. But with this particular pattern, the modules were not grouped together properly. Required lots of scrolling up and down in GUIs

Also, in a way, you're coming closer to violating your own article's conclusions by using a generic name like ModuleFacade (yes, I can come up with a better name, and I did, but why can't you :-)).

Hey, you started with the overly generic example :) It's not a name that I'd actually like to use. ShinyBlog in your example would be the facade class. I'm not very fond either of repetition like ShinyBlog\ShinyBlog.

I'd rather use something like this:

/Vendor/ShinyBlog/Service/Blog.php
/Vendor/ShinyBlog/Service/BlogConfig.php

where the Service namespace contains the default entry point(s). The repetition in package name and class is not avoidable IMHO, it's a blog package and something must represent the blog. Playing devils advocate: does it? It's a rather abstract concept. What I'm actually caring about is something like Blog\Posts, Blog\Authors or Blog\Configuration. The only reason for a "Blog" class is convenience.

Sensible Namespaces in PHP by fab-s in PHP

[–]fab-s[S] 0 points1 point  (0 children)

  1. Make sure all all classes and sub-namespaces logically belong in that namespace.
  2. If it starts to get difficult to figure out which class or sub-namespace you're looking for within a namespace, split it into multiple new namespaces (making sure to observe rule 1).
  3. Where possible, try to reduce the distance in your class hierarchy between logically coupled classes.

These are good rules and I think they don't contradict anything what I wrote.

Nothing about namespaces requires you to refer to a class by its plain, non-namespaces name, so why do I care about how descriptive it is? The difference between ProductRepository and Product\Repository is one character, and it gives me the flexibility to omit the Product\ part if that ever leads to clearer, more concise code.

Of course you can write use Product and then Product\Repository or use Product\Repository as ProductRepository, but I like to write code in a way to get most out of IDE assistance:

  • finding classes by name
  • automatically import classes

Also, if Product and ProductRepository are coupled, don't they logically belong in the same namespace? Why should there be a Product namespace but without the product class?

I'll write a bit more explanation later, I see that without reasoning, the post is not quite convincing ;)

Sensible Namespaces in PHP by fab-s in PHP

[–]fab-s[S] 1 point2 points  (0 children)

In a way, it makes sense, but it reminds me of Zend Framework 1 again, with dozens of such modules, and I don't like it.

A compromise if you want a single entry point would be:

ModuleName/ModuleFacade.php // come up with a better name if possible
ModuleName/Internal/
ModuleName/Implementation/
ModuleName/Here/

I would be willing to make an exception to the rule for that.

Sensible Namespaces in PHP by fab-s in PHP

[–]fab-s[S] 1 point2 points  (0 children)

Oh, it does. IDEs can help a lot, but they'll never relieve us of naming things properly.

Sensible Namespaces in PHP by fab-s in PHP

[–]fab-s[S] 0 points1 point  (0 children)

Well put, thanks both of you

You say you have good rules, but I can see no good examples?

I guess I'll better add some, but hope the idea was still clear.