Daily WTF: PHP “Annotations”

by jmorris 3. November 2012 21:08

Annotations or Attributes (Java vs. .NET/C#) are a means of decorating classes, methods and properties with additional metadata or declarative information. The annotations/attributes can then be queried at runtime via reflection and methods associated with them can be invoked.

Incredibly powerful and useful, they are quite common in various frameworks for tasks associate with say validating data associated with a class or property or for mapping properties on an entity to column names in a table in an RDBMS. There are many, many other uses as well.

Here is an example in C#: https://github.com/jeffrymorris/attributes-example

image

Note that in both Java and C#, annotations/attributes are a first class language construct. This is useful for many reasons, including improved readability and comprehension, they are type-safe, you can attach a debugger and step into them, etc.

Today I learned that PHP also has a form of annotations…well, sort of! It seems that a couple of PHP frameworks (Symphony 2 and Doctrine 2) have “implemented” them not as a language construct but as a hack via comments:

image

Folks, those aren’t comments…that is code that will get executed! Yuck, this is wrong in so many ways…especially since there is an RFC for adding annotations to PHP in the works: https://wiki.php.net/rfc/annotations.

Just because you can, doesn’t mean you should!

Tags:

rant

Eclipse UX…to be desired

by jmorris 14. June 2012 10:50

image

Not much more to say about Eclipse…

Tags:

rant

Obama’s Website Reminds me of Couchbase’s and other Notes

by jmorris 15. December 2011 13:32

This is what inspires me to blog again after months of inactivity:

image image

Is it just me or don’t they, kind of look alike?

That observation aside, the Obama website is kind of creepy. It has an several forms for soliciting contact information from the sheeple:

http://my.barackobama.com/page/signup/who-would-you-bring

And this one which collects more data, allows you to make a donation and enter a Republican you knows contact info and they will send them a message:

“This holiday season, we're giving you a chance to have a little fun at the expense of a Republican in your life by letting them know they inspired you to make a donation to the Obama campaign.

Simply enter their name and email address below. Then, we'll send them a message letting them know they inspired you to donate. (Don't worry—we won't hold on to any of their information.)”

Immature and trite, if not weird action from the POTUS…meh politics.

Another interesting “feature” of the website is this splash page that comes up the first time you hit the site (try clearing cookies):

image

Note that it attempts to immediately get your email and zipcode? More point-of-contact and demographic information for the the big “B’s” big data machine. Notice how small the “continue to the website…” part is? It’s even in a muted color (in comparison to the “SHOP NOW” button).

Inspiration, wherever it may find me…

Tags:

rant

Twitter Fail

by jmorris 12. September 2011 05:50

image

I find it hard to believe that twitter is still experiencing problems of scale given it’s popularity and available resources. Mind boggling, really.

Tags:

rant

UH, OH!

by jmorris 30. August 2011 20:05

image

image 

image

Looks like the cloud evaporated…

Tags:

rant

What Am I Missing Here?

by jmorris 9. March 2011 07:16

So I am trying to purchase VS2010 for home use, side projects, etc…I google VS2010 price and click on the first “relevant” result: http://www.microsoft.com/visualstudio/en-us/products/2010-editions/professional

And click the “BUY NOW” link which opens:

image

Great $549 for VS2010, way to expensive but within the budget. So click on the link to purchase and this is what I am presented:

image

$799.00? WTF? But wait, full version $549.00 (my only option, really). And what do I see in the cart?

image

Fantastic….

Tags:

rant

ActiveMQ: Topics vs. Queues

by jmorris 9. February 2011 13:47

The JMS specification defines two different ways of defining message destinations: Queues and Topics. Understanding the behavior of each is vital to implementing messaging within a system and fulfilling any expectations of message availability.

First a quick aside, the purpose of this post is mostly to keep myself from committing the mistakes I made today based upon invalid assumptions regarding the availability messages sent to a queue within an environment with multiple listeners. In a nutshell, I was writing a test to queue up a single message and I have a listener within the test receive the message.  For some reason the message was never being received…baffling given the simplicity of the test and the maturity of the code.

Here is the test (ignore that the test is not well written, I just want to quickly test that the code works while I am developing):

image

I edited this code a bit for simplicity, but in essence a message should be pumped to the console and displayed (real test validates that message was received after x seconds delay). The only problem was I that I was getting nada…note that I am not testing the queuing API itself, I am testing that the strategy will push a message onto the queue without throwing an exception. It’s basically a throwaway test to prove that it works as expected in an integrated environment.

The problem was that the message was never being received by the listener (QueueReceiver is the listener), however other similar tests that are messaging API specific were working as expected. Running through the usual checks turned up nothing. The code simple didn’t work…but only for this test! Swapping out for another queue worked perfectly :(

Fool me once, shame on you. Fool me twice…

So, what was causing the problem? Well it all became very clear once I went back and reflected on the basics of JMS messaging and the differences in how messages are delivered to queues and topics.

The JMS specification supports two models for sending messages: point-to-point for queues and publish and subscribe for topics. In a nutshell, only one consumer of a queue will receive a messaging regardless of the number of consumers; round-robin message dispersal. Whereas a topic broadcasts a copy of the message to every registered consumer.

It turns out out that I had a windows service running that was a consumer of the same queue and It was the first listener, so it always got the first message. The unit test never received a copy because only one message was sent and the consumer on the windows service always pulled it off. This was proved by simply calling publish twice:

image

This consumer (_receiver) got the second message, because the first one was consumed by the windows service and the next round-robin listener was this unit test. ARGGGHHHH, what a waste of time and brain power!

Lessons learnt:

  1. Don’t write unit tests with external dependencies and assume they will behave as expected
  2. Don’t use shared queues for testing
  3. Don’t forget the difference between queues and topics

References

Tags:

Apache.NMS, JMS | rant

.NET Framework 4 Client Profile: The Devil Itself!

by jmorris 7. January 2011 02:16

I am convinced that Microsoft’s decision to set the build profile of projects created with the Console Application template to “.NET 4 Client Profile” is a work of the devil itself! Why you might ask? Because it is set to this profile by default and because it will cause projects that should rightfully compile to fail, without an adequate explanation of why!

The reason this happens is because VS 2010 will allow you to reference projects and/or DLLs compiled under the “.NET 4 Framework” target, which may contain references to resources excluded by the “.NET 4 Client Profile” without complaining or warning the user. What a horrible, frustrating “feature”…

Here is a formal description from MSDN:

“The .NET Framework 4 Client Profile is a subset of the .NET Framework 4 that is optimized for client applications. It provides functionality for most client applications, including Windows Presentation Foundation (WPF), Windows Forms, Windows Communication Foundation (WCF), and ClickOnce features. This enables faster deployment and a smaller install package for applications that target the .NET Framework 4 Client Profile.”MSDN

Here is an example of a compile time error caused by this:

image 

The weird, confusing part is that while typing in the using statement for the namespace, intellisense will show you the namespaces and the object viewer will confirm that they exist. However, when you go to compile it will fail! Very frustrating!!!

This fix is very easy, simply right click on the project and select properties and then in the “Target Framework” dropdown, select “.NET 4 Framework” and your good to go. I am hoping that this will be fixed or changed in VS2010 SP1 that should be released soon.

Tags: , , , ,

rant | Visual Studio

Design Fail

by jmorris 28. October 2010 13:59

While I am not much of a front end developer or much less a designer,  the design elements of some sites are so poor, that even I shake my head in disbelief. While doing some research for a future post on refactoring and method groups, I came across this site: www.thedesignmethodgroup.com

image 

Note that the site is all flash and you navigate with that teeny, tiny little menu thing!  As you click the on the menu item squares the flash app moves another layer into focus which contains quotes from various famous people. The problem is, WTF does the company even do? It took me awhile navigating through this maze to find out they are a marketing company…apparently the focus on “creating customers”. Maybe the should focus on “communicating with customers” first.

BTW, here is the “Clients Page”:

image

Is it any wonder?

Tags: , ,

rant

ViewState Fail…

by jmorris 13. October 2010 01:30

image

I _really_ despise ViewState…from the page bloat to the innocuous ViewStateException errors that litter my logs: “The state information is invalid for this page and might be corrupted”. For the little bit of good it does persisting state between postbacks, it causes huge amounts of grief…I guarantee I have spent more time circumventing it’s grasp than embracing it’s utility.

Tags: , ,

rant

Jeff Morris

Tag cloud

Month List

Page List