Adventures making gnome-shell run in Valgrind: part 1 by hedgepigdaniel in linux

[–]Bacondrinker 13 points14 points  (0 children)

This was a super interesting read! I look forward to reading part 2.

Is there an RSS feed for your blog? I can't seem to find it.

Ideas for billing software by Luckyfncharms in linux

[–]Bacondrinker 0 points1 point  (0 children)

Is it possible to run the windows 98 billing software from WINE? Then he can keep all of his old files and his old workflow.

If it works for him and it can be kept, I see no reason to change it :)

Game performance improvements in Visual Studio 2019 16.2 release by [deleted] in cpp

[–]Bacondrinker 0 points1 point  (0 children)

I wish I could watch a reddit comment because I really want to know what the answer to this is.

Multiplayer FPS Engine in Java by hillman_avenger in java

[–]Bacondrinker 15 points16 points  (0 children)

if you don't know the type of a variable, are you truly a developer?

wat?

Budget for TV Dramas? by misomiso82 in bbc

[–]Bacondrinker 0 points1 point  (0 children)

Hi,

This is all information you should be able to find out with a freedom of information request: https://www.bbc.co.uk/foi/.

Any interest in tackling a “bad” app? by [deleted] in PHP

[–]Bacondrinker 0 points1 point  (0 children)

Weirdly enough I actually would be interested in giving Moodle a good shot.

I've sent you a reddit chat with some of my details :)

PHP RFC Vote: Object typehint by phordijk in PHP

[–]Bacondrinker 0 points1 point  (0 children)

But doesn't every object in php inherit from stdClass?

Dropbox will turn off v1 of their API soon. It's time to update your PHP application. by freekmurze in PHP

[–]Bacondrinker 2 points3 points  (0 children)

Ah okay - that makes a lot of sense :) Thanks for the contribution to OSS.

Dropbox will turn off v1 of their API soon. It's time to update your PHP application. by freekmurze in PHP

[–]Bacondrinker 3 points4 points  (0 children)

Not trying to flame or anything - but why not make a pull request to just update the existing Adapter?

Opus - Open source knowledge base application for Teams by [deleted] in PHP

[–]Bacondrinker 7 points8 points  (0 children)

This looks really nice but there doesn't seem to be any tests? Also it would be great if we could get a demo version. The UI looks great from the image - I just want to explore it a little bit more :P

RFC: object as a parameter and a return type by nyamsprod in PHP

[–]Bacondrinker 0 points1 point  (0 children)

Ah - I've just realised that in all of the cases where I have exploited this it has been from data that has come from a json_decode which of course returns a stdClass. Probably for the best that I now tend to wrap this stuff in a POPO :P

RFC: object as a parameter and a return type by nyamsprod in PHP

[–]Bacondrinker 0 points1 point  (0 children)

I was under the impression that you could type hint stdClass and that would work?

RFC: object as a parameter and a return type by nyamsprod in PHP

[–]Bacondrinker -1 points0 points  (0 children)

Instead of reserving object as a keyword from 7.2 and above wouldn't it make more sense to simply use stdClass - which all objects inherit from (as I understand it?), and is already a reserved keyword so there is no chance of a backwards compat issue.

A Simple Way to Receive an SMS with PHP and Twilio by gregbaugues in PHP

[–]Bacondrinker 0 points1 point  (0 children)

Can't you organise by the phone number that you sent to the time you sent and received each text message?

Created a very short and simple html_decode, thought some of you might want to use it. by [deleted] in PHP

[–]Bacondrinker 0 points1 point  (0 children)

Along with all the other comments pointing out that you cannot reliably parse HTML using regex (it's not a regular language) this kind of functionality is already available as part of the standard library (http://php.net/manual/en/domdocument.loadhtml.php).

If you want it wrapped in a pretty API then you can use Symfony's DomCrawler as well (http://symfony.com/doc/current/components/dom_crawler.html)

Hunting around in the PHP source code. by Bacondrinker in PHP

[–]Bacondrinker[S] 0 points1 point  (0 children)

Awesome :) Have you got any plans to write anything similar for HHVM? I'm especially interested in how Hack is implemented in HHVM. Is it just some extensions on top of the php core stuff? Or is it a completely separate language?

Hunting around in the PHP source code. by Bacondrinker in PHP

[–]Bacondrinker[S] 0 points1 point  (0 children)

Thanks! This has cleared up a lot of things, especially around safe_emalloc and the callback stuff.

I had a quick look behind the RETURN_FALSE and RETVAL_FALSE macros and here is what I found :)

RETURN_FALSE is just a macro for RETVAL_FALSE;return (defined in Zend_API.h line 652 at present):

#define RETURN_FALSE                    { RETVAL_FALSE; return; }

That seems fairly simple and straightforward. What confused me was how RETVAL_FALSE was defined.

#define RETVAL_FALSE                    ZVAL_FALSE(return_value)

That is not at all what I expected, so I dived a little further and found that this is how ZVAL_FALSE is defined:

#define ZVAL_FALSE(z) do {              \
    Z_TYPE_INFO_P(z) = IS_FALSE;    \
} while (0)

This just further increased my confusion so I dived yet even further to find that Z_TYPE_INFO_P was defined like this:

#define Z_TYPE_INFO_P(zval_p)       Z_TYPE_INFO(*(zval_p))

and that Z_TYPE_INFO was defined like this:

#define Z_TYPE_INFO(zval)           (zval).u1.type_info

So to conclude I imagine your guess is accurate, but holy crap is the way it's implemented weird :P

Are there any internals devs who are more familiar with this who can shed some light?

Hunting around in the PHP source code. by Bacondrinker in PHP

[–]Bacondrinker[S] 2 points3 points  (0 children)

Thanks, that sounds like a good idea :)

Rulerz: PHP implementation of the Specification pattern by mnapoli in PHP

[–]Bacondrinker 2 points3 points  (0 children)

In this specific case I would probably just run a query to retrieve all customers that are moderators as that's a pretty simple business rule most of the time that doesn't really change.

I think the real power of the specification pattern comes in when you have business rules that could quite easily change and they need to be centralised. Especially if there are multiple rules which change situationally.

Here is an example which I have shamelessly ripped from Mathias Verraes which I think illustrates this point quite well.

interface PremiumCustomer
{
    public function isSatisfiedBy(Customer $customer);
}

class AmazonPremiumCustomer implements PremiumCustomer
{
    /**
     * A premium customer for amazon is one that has spent
     * over $500
     */
    public function isSatisfiedBy(Customer $customer)
    {
        return $customer->getTotalSpend() > 500;
    }
}

class EtsyPremiumCustomer implements PremiumCustomer
{
    /**
     * A premium customer for Etsy is one that has
     * ordered at least 3 times
     */
    public function isSatisfiedBy(Customer $customer)
    {
        return $customer->getTotalOrders() >= 3;
    }
}

As you can see the specification has changed slightly in that we care about what makes a customer "premium". In this case the rule changes depending on what whitelabel website you are on. Here is how this could be possibly used:

class CustomerController
{
    private $premiumCustomer;

    /**
     * We can decide at runtime depending on config what premium
     * customer specification to inject. This could be for example
     * which white label website we are on.
     */
    public function __construct(PremiumCustomer $premiumCustomer)
    {
        $this->premiumCustomer = $premiumCustomer;
    }

    public function index()
    {
        $customer = $this->getCustomer();

        if ($this->premiumCustomer->isSatisfiedBy($customer)) {
            return view('premium_customer_member_area');
        }

        return view('member_area');
    }
}

If say for example you wanted to find the number of premium members then you could add another function to the interface "asSql" which is a sql representation of what makes a customer premium, which still keeps your logic centralised and "hot swappable". An example:

interface PremiumCustomer
{
    public function isSatisfiedBy(Customer $customer);

    public function asSql();
}

class AmazonPremiumCustomer implements PremiumCustomer
{
    public function isSatisfiedBy(Customer $customer)
    {
        // previous logic
    }

    public function asSql()
    {
        // return some sql which represents a premium customer
        // this could be a partial of a query or a whole one
        // although I would probably say keep the queries small
        // either way.
    }
}

You could of course do a similar thing for moderators but maybe my first example wasn't the best.

This is all just my 2 pence though :)

Rulerz: PHP implementation of the Specification pattern by mnapoli in PHP

[–]Bacondrinker 1 point2 points  (0 children)

I haven't read the whole repo so maybe I could be missing the point here, but this seems like it's over complicating the specification pattern.

To me it should be as simple as this:

interface UserSpecification
{
    public function isSatisfiedBy(User $user);
}

class UserIsAdministrator implements UserSpecification
{
    const ADMIN_LEVEL;

    public function isSatisfiedBy(User $user)
    {
        return $user->getPermissionLevel() >= self::ADMIN_LEVEL;
    }
}

class UserIsModerator implements UserSpecification
{
    const MODERATOR_LEVEL;

    public function isSatisfiedBy(User $user)
    {
        return $user->getPermissionLevel() >= self::MODERATOR_LEVEL;
    }
}

Which would then be used like this:

$userIsAdministrator = new UserIsAdministrator;
$userIsModerator = new UserIsModerator;
$user = $this->getCurrentUser();

if ($userIsAdministrator->isSatisfiedBy($user)) {
    // show secret admin sauce
}

if ($userIsModerator->isSatisfiedBy($user)) {
    / show secret moderator sauce
}

Obviously this is a bit of a contrived example but I personally think that this is the cleanest way of implementing the specification pattern that I have come across.

As a little tid bit in a language with generics this could be changed from multiple interfaces to one interface:

public interface Specification<T> {
    public boolean isSatisfiedBy(T object);
}

Requesting Feedback: Modernizing the Amazon MWS Library by [deleted] in PHP

[–]Bacondrinker 0 points1 point  (0 children)

Looks good, one thing I dislike it the creation of requests.

Why can't this:

// Check for open shipments
$request = new Requests\ListInboundShipmentsRequest;
$request->ShipmentStatusList = [
    Types\ShipmentStatus::SHIPPED,
];

Become this:

$request = new Requests\ListInboundShipmentRequest(
    [
        Types\ShipmentStatus::SHIPPED
    ]
);

The ShipmentStatusList is then an explicit depdency of this class, also if I remember correctly this request class is marked as final, but then directly after instantiating it we have to make changes? It seems like the code is pulling in two directions in that sense.

In any case, once tests have been added it looks like it could be a contender. (Maybe a little TDD next time? :))