Categories
Code Programming WordPress

__DIR__ vs dirname( __FILE__ )

Calling a constant should always be faster than a function call, right? PHP contains two different ways to get the directory that a file is currently in. __DIR__ is a magic constant added to PHP in 5.3. The official PHP documentation specifically states: “This is equivalent to dirname(__FILE__).” Equivalent in return doesn’t necessarily mean equivalent in performance though, so I decided to test the performance of both accross a couple of variables.

Testing Methodology

When running lots of tests, I’ve found that travis-ci can be a big helper. You can define the matrix of the tests you want to run as your testing matrix and then use the results. So I setup a repo for my tests. The repo contains four main pieces:

  1. A file generator which creates the code I’ll actually run the performance test on.
  2. A test running script which runs the actual tests.
  3. The travis.yml file to define my tests matrix
  4. Files used for the actual test. This is not linked, there are 400,000 files. The generator shows them off.

My test calls the function I am looking for 100,000 each. One run has all the files in 1 directory, and the other has one file per directory. I wanted to rule out the possibility that a single directory could affect this call.

I ran this test on six version of PHP: 5.6.40, 7.0.33, 7.1.27, 7.2.15, 7.3.9 and 7.4-dev. Each test did 650 runs and I looked at the user time for each of those runs. This means that I called both __dir__ and dirname( __file__ ) 130,000,000 times each. I then took the times for each of these runs and looked at that maximum (slowest) run for each and the 95% time ( the average between the 618th and 619th slowest) to rule out any extreme cases. Overall, the results between maximum and 95% are similar.

User is the amount of CPU time spent in user-mode code (outside the kernel) within the process. This is only actual CPU time used in executing the process. Other processes and time the process spends blocked do not count towards this figure.

Stack Overflow

__DIR__ vs dirname( __FILE__) Test Results

95% performance

Script5.67.07.17.27.37.4
dir ( 1 folder)1.42.762.082.512.271.3615
dir ( many folders)1.382.292.552.36152.651.57
dirname( 1 folder)1.58152.272.74153.242.411.5215
dirname( many folders)1.682.292.08153.292.68151.87

Overall, the results show that __dir__ is generally faster, but it’s rarely much faster. Consider that in the slowest run ( using PHP 7.2 and calling dirname( __FILE__ ) on multiple folders), each call took 0.0000329 seconds. The fastest run was 2 hundred-thousandths of a second faster. This is such a micro optimization that except under extreme scale, it’s unlikely you will ever notice a difference. That said, under most versions of PHP, __DIR__ is faster.

So: __dir__ or dirname?

At the end of the day, the performance of __DIR__ is ever so slightly better, but more importantly I think it’s clearer and easier to read. So I’m on team __dir__, but the performance is only a bonus.

If you have a different thought, or think that my testing methodology could be improved, please let me know in the comments below.

Categories
WordPress

This might be the first post ever published on WordPress using PHP7.4.

I have every reason to believe that this is the first post ever published on WordPress using PHP7.4. It’s likely coming a bit premature, but if you aren’t willing to have some fun, then why maintain upstream language compatibility of an open source project. I’ve worked on php version support in WordPress since PHP7.0 and made the first post using WordPress on php7.3, so this is becoming a fun tradition.

Yesterday I added code to WordPress core to fix a number of deprecations in PHP7.4. PHP7.4 is scheduled to be released on November 28, which is 74 days and 5 release candidates away. The goal for WordPress is that version 5.3 will fully support PHP7.4 and that version is scheduled to be released 12 November 2019.

The biggest deprecations in 7.4 that affect WordPress core are around magic quotes and

For plugin and theme authors, you’ll want to look into:

PHP7.4 features for WordPress Developers

It’s not just deprecations in PHP7.4 that WordPress developers can look forward to, but the PHP internals team has added some new features for us to use as well.

Typed Properties continue the evolution of PHP’s type system to allow for class properties to be type strict. The only Property types you can’t use are void and callable, otherwise every type decleration is supported.

Arrow Functions allow for simpler anonymous functions. I recommend only using these in callbacks such as with array_map in order to make your debugging simpler.

Coalescing Assignment is here as syntactical sugar. ??= allows for you to add default values easier.

If you see any errors or notices on this site, let me know in the comments. Assuming this actually publishes, then WordPress can be used with PHP7.4, but I only recommend it for those feeling especially adventurous.

Categories
Art Programming WordPress

Art and Commit Messages: Volume 2

Last year I published volume 1 of Art And Commit messages and sold nearly 50 copies! For my first zine, I was ecstatic that so many people were willing to spend $3 on something so unknown. I have already started thinking about Volume 2 and think that it will be a great thing to publish at WordCamp US. I’m also thinking it might make sense to include some different things this time.

Art by more Artists

Volume 1 featured my art, for Volume 2 I would like to feature the art by more artists. I am also thinking of budgeting a small amount so that artists are compensated, but as Volume 1 didn’t make any money I think this is going to be a low amount. Maybe $50 for each piece.

Are you interested in having your artwork featured in Art and Commit Messages? Let me know:

Essays by More Writers

Along the same lines, I want to feature a couple of essays about commit messages from a variety of people. What kind of essays would you like to see in volume 2?

Finally, I want to figure out some sort of game to include. Maybe I loved reading Highlights for Children too much as a kid, but I think a game would be fun.

Art and Commit Messages: Strange Bedfellows

Art and Commit Messages might feel like an odd combination but the best of both are snapshots that convey an intent. Art transposes the emotion of the creator to an audience. It can transport you into the brain of the artist. The best commit messages similarly transport you into the brain of the creator. They share the coders intent.

That’s the message from the cover of volume 1. I absolutely recognize the odd combination, but they are two things that I care about and I hope that by combining these two strange bedfellows I can encourage people to write better commit messages.

Overall, my goal remains to encourage high quality commit messages through education, entertainment, and an understanding of history. I’m not looking to make money, if I was I wouldn’t be making a zine.

Do you have other ideas for making Art and Commit Messages better? Leave a comment or get it touch and let me know!

Categories
mostly pointless. WordPress

An adventure with a super useless one-liner to find the most common words in WordPress commit messages

I read some insight into Drupal committing and they had a chart of the most common words in drupal commit messages. I thought it would be interesting to do something like that with WordPress Core, so I through together a bash one-liner to find this. It’s not the most eloquent solution, but it answers the question that I had. Here is what I initially came up with.

svn log http://develop.svn.wordpress.org/trunk -rHEAD:1 -v --xml | xq '.log.logentry | .[].msg' | sed 's/.$//' | sed 's/^.//' | sed 's/\\n/ /g' |  tr ' \t' '\n' | tr '[:upper:]' '[:lower:]' | sort | uniq -c | sort -nr | head -n 25

Let’s walk through this since there is enough piping going on, that it may not be the easiest to follow.

svn log http://develop.svn.wordpress.org/trunk -rHEAD:1 -v --xml

I start by getting an xml version of the SVN history, starting at the first changeset and going until the current head.

xq '.log.logentry | .[].msg'

Next, I use xq which takes xml and allows me to run jq commands on it. It’s a handy tool if you ever need to use xml data on the command line. In this case, I am taking what is inside <log><logentry> and then for each sub element, extracting the msg. At this point, the messages are on a single line wrapped in quotation marks with \n to signify newlines. So I run three seds to fix that up.

 sed 's/.$//' | sed 's/^.//' | sed 's/\\n/ /g'

I’m sure there is a better way to do this, but the first one removes the last character, the next one removes the first character, and the last one converts new lines to spaces. Since words are what we are aiming to look at, we need to get all the words onto their own lines.

 tr ' \t' '\n'

tr is a powerful program for doing transforms of text. In this case, I am taking whitespace and turning it into actual newlines (rather than just the new line charachters). There is likely a more elegant way to have solved this, but my goal isn’t the best solution it’s the working one.

tr '[:upper:]' '[:lower:]'

Word and word are not equal, so we need to make everything a single case. In this case, I am again using tr, but now I am transforming upper case characters to lowercase.

sort | uniq -c | sort -nr | head -n 25

Counting things on the command line is something I have done so many times, I have an alias for a version of this. Sort puts everything in alphabetical order, uniq -c then counts how many uniq values there are and outputs it along with how many of each it counted. uniq requires things common things to be in adjacent lines, hence the initial sort. Next up, we want to sort based on the number and we want high numbers first. Finally, we output the top 25.

 28997 the
 27463 
 20429 fixes
 17844 to
 17818 props
 15251 for
 15189 in
 14441 see
 10856 and
 10272 a
 7549 of
 5594 is
 5227 when
 5133 add
 4444 from
 4143 fix
 3847 *
 3821 on
 3489 use
 3320 that
 3267 this
 3064 with
 3043 remove
 2983 be
 2766 as 

That’s not super helpful. The isn’t my idea of interesting. So I guess I need to remove useless words. Since I have groff on this machine, I can use that and fgrep

 fgrep -v -w -f /usr/share/groff/1.19.2/eign

I also noticed that the second most common word is whitespace. Remember when we used to put two spaces between sentences? WordPress Core commit messages remember. So let’s add another sed command to the chain:

sed '/^$/d'

And now the final command to see the 25 most used words in WordPress Core Commit messages:

svn log http://develop.svn.wordpress.org/trunk -rHEAD:1 -v --xml | xq '.log.logentry | .[].msg' | sed 's/.$//' | sed 's/^.//' | sed 's/\\n/ /g' | tr '[:upper:]' '[:lower:]' | tr ' \t' '\n' | fgrep -v -w -f /usr/share/groff/1.19.2/eign | sed '/^$/d' | sort | uniq -c | sort -nr | head -n 25

And since you’ve made it this far, here is the list

 20429 fixes
 17818 props
 15189 in
 5594 is
 5133 add
 4143 fix
 3847 *
 3320 that
 3267 this
 3064 with
 3043 remove
 2766 as
 2435 an
 2432 it
 2109 post
 2103 if
 2080 are
 1889 don't
 1793 update
 1735 -
 1688 twenty
 1523 more
 1500 make
 1471 docs:
 1416 some 

Have an idea for another way to do this with the command line? I would love to hear it.

Categories
WordPress

Mobile Block editor – Initial Thoughts

I’m writing this using a beta version of the WordPress iOS mobile app that integrates Gutenberg. It is fairly stripped down as far as blpacks go.

While this site has blocks from multiple plugins (including Gutenberg so I can try the latest features), the app has much fewer options.

Blocks available from the mobile app

I was definitely surprised to not see all the core blocks, especially not to see my reusable blocks that I have saved to the site.

Another thing that surprised me as a power user is that slash commands for new blocks don’t work.

I also can’t figure out how to access the block inspector to save options on differnet blocks.

Opening up posts with blocks in them other than this initial set shows those blocks as “unavailable”. This includes all the embed blocks.

Unsupported is the new black

The responsiveness of the editor is amazing, and the ability to move blocks up and down makes editing inside the mobile app much easier.

Overall, as a version 1, I like it. I also think that it has long way to go before I will abandon opening a mobile browser for the majority of my on the go blogging.

Categories
WordPress

To Viper

My first interactions with Alex were in the #wordpress IRC channel, likely him helping me with some code. Over the coarse of a couple of months, we joked around and chatted code. At some point the mention of his username prompted the question of if he had a Viper, but I found out he didn’t even have a driver’s license! I didn’t even realize that this person I was becoming friends with lived in my city, but when I mentioned WordCamp Portland I found out I would actually get to meet him in person. Alex became the first person I met through WordPress chats that I got to meet in person.

At WordCamp Portland 2009, Alex led an unconference session on Advanced WordPress development. I think that Matt Mullenweg might have been the one who put Alex’s name on board and pushed him to lead the discussion. It was during this session that I was first introduced to the idea of custom post types. This event was one of the most important events on my journey to were I am today, and Alex leading a discussion was a part of it.

The following year at WordCamp Portland 2010, I gave the final session of the second day. The room was half empty at this point, but Alex had stuck around to support me. Unfortunately, Alex might have been more exhausted than he had let on as I remember looking at him at one point and seeing him asleep. For a couple years, I encouraged him to give a talk at a WordCamp so I could fall asleep in it.

In 2011 at WordCamp San Francisco a small group of us headed out in search of dinner. This is when I found out that Alex was the opposite of an adventurous eater. We discussed multiple places before heading to some chain restaurant that had cheese pizza and I got to enjoy one of Alex’s favorite dishes, but more importantly I got to enjoy a meal with him.

Alex and I continued our conversations for years. We never were close friends, but we always remained friends. After his initial diagnoses with Leukemia, I wrote some unit tests with Alex in mind. Alex’s contributions to WordPress were numerous, and his contributions to my life are unforgettable. Whenever I see a Viper, I’ll forever think of a man who was obsessed with cars but didn’t get his license until his mid twenties. Tonight I raise my glass to Alex, Viper007Bond, Mills.

Categories
Art Code Four Short Things WordPress

Four Short Things – 23 February 2019

Inspired by O’reilly’s Four Short Links, here are some of the things I’ve seen, read, or watched recently.

Leukemia has won

WordPress has allowed me the opportunity to meet hundreds of people first online and then offline, but Alex “Viper007Bond” was the first. When I first started getting involved in WordPress, I spent many late nights in the IRC #wordpress channel on freenode, at first seeking help but then providing it. Viper was commonly there helping others and likely answered more than a few questions of mine as well. He’s been publicly battling leukemia for 2.5 years. His blog is a great tale of the ups and downs of cancer. Alex and those that care about him are in my thoughts right now.

Kevin Beasley: A view of a Landscape

On view at the Whitney until 10 March, this exhibit on the top floor is one encompassing sound and visuals. Featuring the motor from a cotton gin and giant sculptures with Cotton, it explores race, history and the evolution of America.

Writing CSS Algorithms

Lara has done more to change my opinions on CSS than anyone else. This post is a companion piece to a talk she gave at WordCamp US and one that everyone web developer should read.

Pento hits 1000 Commits

13 people have made over 1000 commits to WordPress core over the past nearly 16 years. Gary Pendergast joined the club during the 5.1 release. Overall, there have been 44767 commits so Gary’s count only represents 2.2% of the total activity.

Four Short Things is a series where I post a small collection of links to art, news, articles, videos and other things that are me. Follow my RSS feed to see Four Short Things whenver it comes out.

Categories
WordPress

WordCamp US: FAQ

We are just a few days away from WordCamp US! This will be the fourth WordCamp US, and I’m excited to be attending my fourth WordCamp US. To help you know what to expect, here are a few questions and my opinions to go along with them.  

Last year I was a rockstar Wapuu. 
How many people will be there?

A look at the attendees’ page show 1389 people registered as of today. While not everyone will show up or stay the entire time, there will likely be over 1000 people interested in WordPress at the Music City Center this weekend. 

I’ve been to a WordCamp in my city before, should I expect the same thing? 

I’ve attended over 30 WordCamps, and WordCamp US is a different class of events than the local camps. In addition to the size (it’s bigger), WordCamp US features a closing “State of the Word” presentation and sponsor booths that are much more than 2 people behind a table with a backdrop. It’s much more like a $1,000 ticket tech conferences than a celebration of the local WordPress community.

What should I do if I see a big name person?

Say Howdy! The WordPress community is an incredibly welcoming place. So if you see a name you recognize, say Howdy. This includes internationally developers such as D Bachhuber

What Talks are you most excited about? 

All of them? 
But since I can’t see them all in person, the three I am most looking forward to are: 
Bridging the Design and Development Gap with CSS Algorithms by Lara Schenck
Metaboxes Considered Harmful by Helen Hou-Sandí
The evolution and future of publishing by Alexis Lloyd

Will anyone want to talk about Gutenberg?

Not this year. Maybe in 2019. 

Should I attend Contributor Dy?

Absolutely! It’s a chance to get behind the scenes and not ust see how the sausage is made, but grind some yourself. 

Will the food be any good?

Most conferences you are happy if one thing is edible, but last year the Music City Center shined when it came to food. This year’s menu is looking as well.

I hope this helps you get as. excited for WordCamp US as. I am. This year I’ll also have copies of. my first zine “Art and Commit Messages” available, so come find me if you want one. 

If you have any questions, ask them and I’ll try my best to answer them. 

Categories
WordPress

WordPress at 15

I came into WordPress like a lot of people: I wanted a blog. I tried and it was lacking, so I googled around and discovered WordPress.  This was 2007, WordPress 2.2 had just been released. Widgets were the hot new thing. Tags were still a few months away from being added to core. It was an entirely different WordPress than we have today.

WordPress has had a giant impact on my every facet of my life since then. In just the last week, I organized a last minute Happy Hour for a friend I made because of WordPress. I sat at the house of a friend enjoying the company of him and his family because I got involved with WordPress. I started a job I got because I got involved in WordPress. I took a friend out for a drink who I met because of WordPress. I wore a bow tie that was given to me with a WordPress logo because I got involved in WordPress. I stayed up entirely too late making Art to celebrate WordPress because I got involved in WordPress.

Above you’ll find 15 mono prints I made in celebration of WordPress’s 15th anniversary. Inspired by the WordPress logo, I based the text on Dalliance, Jason Santa Maria’s inspiration for the original W, before cutting the linoleum and making each print. For the Blue, Black, Orange, and Grey, I used printmaking ink. The green is acrylic paint. I then splatter painted till I was happy with the effect. Each print is hand numbered and signed on both the mat and the back of the print.

Over the coming weeks, I’m hoping to send a few of these off to some of the people who have influenced me the most in the WordPress community. I also think I’ll throw one or two on to raise some money for charity. Comment below if you want me to update you when I do so.

I continue to remain optimistic about the long term success of WordPress. I’m writing this in Gutenberg, where I’ve written almost all my posts over the last year. Five years ago I went to JSConf and the reaction of many people towards hearing I worked on WordPress was that it was amateur. This last week I went to a CSS meetup and the reaction to people hearing I worked on WordPress was respect. Always bet long on WordPress. 

I previously blogged WordPress’s 10th anniversary and hope to blog it’s 20th as well. 

Categories
WordPress

A quick review of Local by Flywheel

I recently decided to check out Local by Flywheel for local development, and my initial thoughts are that it’s strong for many things, but is far from perfect.

In the past, I’ve used MAMP, XAMPP, VVV, and custom docker environments for local development. Each of these has it’s own strengths and weaknesses. Local’s strength is that it is by the far the most user-friendly route to having a local development environment. It’s all GUI driven, you don’t need to mess with hosts files, and having an SSL cert for your local site couldn’t be easier. If your goal is to have a local site with little fuss, Local By Flywheel does it.

Where Local falls short is developer friendliness.  Installing XDebug, for example, isn’t easy. Customizing the environment to include anything beyond the standard config options also isn’t easy. If you are eloper that needs XDebug or wants a PHP Extention that isn’t included out of the box, you are going to need to do some work for it.

Installing the development checkout of WordPress also isn’t straightforward. I would love for it to out of the box support using either the regular or development versions of WordPress. I could see a GUI tool like Local being very valuable for onboarding new WordPress Core Contributors who aren’t as familiar with git, svn, or the command line if it did this. 

Would I recommend Local by Flywheel?

For the right person, yes.  If you wouldn’t call yourself a developer and have no interest in contributing to core, then Local is definitely worth checking out. If you want XDebug, are comfortable on the command line, want to run PHPUnit, or need a nondefault PHP setup, then you likely should look elsewhere.

Have you tried Local by Flywheel?  What are your thoughts on it?