Wednesday, September 10, 2014

C# – Shorten null check around foreach loops

This is another blog post filed under “So I can remember this for next time. If it helps you too, great!”

In C#, when looping over a collection where the collection object itself might be null, if the desired behavior is to just loop zero times if the collection object is null, typical code would be:

List<MyType> list = PopulateList(); // Some method that returns a List<MyType>, or null 
if (list != null) 
  foreach (MyType mt in list) 
    // Do stuff with mt... 

Using the C# null-coalescing operator ??, the above code can be condensed to:

List<MyType> list = PopulateList(); // Some method that returns a List<MyType>, or null
foreach (MyType mt in list ?? Enumerable.Empty<MyType>) 
  // Do stuff with mt... 

In that second example, if list is non-null, then the foreach iterates over it as normal. If list is null, then the foreach iterates over an empty collection -- so zero iterations are performed.

Wednesday, August 06, 2014

Double-click-drag to select entire words

Here’s a quick tip on selecting text with the mouse that I’m blogging as much to help myself remember as to inform you, the reader:

You can double-click-drag – that is, double-click, and continue holding the mouse button on the 2nd click – to select multiple entire words from a block of text.  This obviates the need to position the mouse cursor exactly over the small space between words when selecting entire words or sentences, both when beginning and ending the selection.

Bonus tip: You can triple-click to select an entire line or paragraph of text.  (This one I do remember and use frequently – and get annoyed by those few applications that don’t support it.)

These tips work in most applications on both Windows and Mac.

Wednesday, March 05, 2014

Fix: CSS border-radius not working in Internet Explorer 11

In doing browser compatibility testing in a new web form I was developing on my PC this morning, the form looked great in all browsers I had on my local Windows 8.1 PC – except for Internet Explorer 11, where it looked awful: div and form field border corners were squared instead of rounded, form fields rendered with excess height, some text was slightly truncated, and a few other issues.

When I looked at the CSS styles in use on the page in IE11’s built-in F12 developer tools, I noticed that the border-radius property on my form’s enclosing div was present, but it was missing its enable/disable checkbox, and the name of the style was shown with a red squiggle underline, as though IE didn’t recognize it.  It seemed almost as though IE11 was behaving like a legacy browser that didn’t recognize that newer CSS property.

In fact, that did turn out to be exactly the problem. IE11 was rendering the form (running on my local IIS) with its legacy “Compatibility View” engine, which it is by default configured to do for intranet sites.  (Oddly, my IE11 was not using Compatibility View to render another copy of the form that I was trying to use to debug the issue that I had IE loading via the “localhost” domain, which had me confused for a while.)

The solution was to disable IE11’s Compatibility View for intranet sites by doing Setting (gear icon) > Compatibility View Settings > uncheck “Display intranet sites in Compatibility View” checkbox.  Making that configuration change immediately got IE11 to start rendering the page properly.

Tuesday, January 14, 2014

ATG BCC – “Unknown Segment ‘Main’” log error; missing menu items in left nav

This post details a problem, and its corresponding solution, that my team encountered and recently resolved in the ATG 9.3 BCC application.


  1. In the BCC application, in the left nav menu, several of the menu items that should be present are missing, including:
    • Content Administration | Automated Deploy
    • Content Administration | Content Administration Project
    • Merchandising | Manage Commerce Assets
    • Personalization | Targeting and Segmentation
  2. When a user successfully logs into the BCC application, lots of errors like the following are logged in the CA application’s log file: atg.process.ProcessException: Unknown segment "main" in process /Content Administration/CA.wdl at atg.process.ProcessManagerService.getSegmentInfo( at atg.process.ProcessManagerService.createProcessInstanceInfo( at atg.process.ProcessManagerService.getProcessInstanceInfos( ...
  3. When the CA instance is initially started, some errors like the following that mention “atg.nucleus.ServiceException” and “dynamoMessagingSystem.xml” appear in the CA application’s log file: atg.nucleus.ServiceException: Destination "sqldms:/Price/CacheInvalidation" is not found for output port "PriceCacheInvalidator" of "message-source" element with Nucleus name "/com/example/ecom/messaging/PriceCacheMessageSource" for patch bay definition file "/atg/dynamo/messaging/dynamoMessagingSystem.xml" at atg.dms.patchbay.PatchBayManager.createOutputDestination( at atg.dms.patchbay.PatchBayManager.createOutputPorts( ...


(This solution worked for my team’s application; YMMV.)

In one of the dynamoMessagingSystem.xml files in our project’s source code, as child elements of the patchbay XML element, there were message-source and message-sink elements (and sub-elements) that were (apparently) incorrectly defined, and also were not actually being used by the application. 

Removing those bad elements from the dynamoMessagingSystem.xml file, and then rebuilding and redeploying the application, resolved the issue.

Thanks to Miles from Oracle Support for his assistance in troubleshooting this issue!

Monday, December 30, 2013

Upgrade impressions: iPhone 5S vs iPod Touch 5 + dumbphone

Between early 2011 and November 2013, I carried an Apple iPod Touch (first a 4th gen., and later a 5th gen.) as my primary “pocket device,” along with an old pre-paid “dumbphone” flip phone for making the occasional phone call.  As I’ve blogged previously, my reason for doing this was cost: The iPod Touch had no monthly fee, and the pre-paid phone cost only $7.50/month for about an hour’s worth of talk time, versus about $80/month (about $1,000/year!) for a smartphone with a data plan, accounting for taxes and fees.

For me, the math basically boiled down to trading loss of GPS capability and the ability to access the Internet from non-WiFi locations for keeping an additional $900/year or so in my pocket.  I was more than willing to accept that deal!

However, my job just recently adopted a new policy of providing partial reimbursement to developers with on-call responsibilities for their smartphones, which changed the math quite a bit!  Based on that, I sold my iPod Touch 5th gen on eBay (recovering around $210 of the original $300 purchase price, after shipping and fees – not bad!), and purchased a new iPhone 5S with service from Verizon.

Here are my thoughts on the advantages – and disadvantages – of swapping out my iPod Touch and dumbphone for a new iPhone, after the first month or so of having made the swap.


Internet Anywhere

I was a bit startled the first time I was driving down the road and heard the phone “ding” with a new incoming notification – the iPod Touch only ever did that when I was “stationary” (typically at home or at work)!

The ability to look things up while on-the-go has already helped me out once: While en route to an appointment at a new doctor’s office, I didn’t remember the specific cross-streets of the office location, but I was able to pull out the phone (after pulling the car off the road) and get those looked up with no problem.


I could sort of do texting previously, using a combination of approaches: iMessage on the iPod Touch to connect with other Apple device owners; various email-to-SMS gateways and/or Google Voice to initiate text message conversations with others and receive replies; and (in a pinch) the 10-digit keyboard on the old prepaid dumbphone. It was difficult, however, to make it easy for others to contact me via text message, and also to contact non-Apple folks while out and about.

Now I’ve joined the ranks of people for whom texting is easy! I just give out my phone number, and anyone can text me, and I can receive the message and reply easily wherever I am (except while driving, of course!).


I’ve had a GPS on my wish list for a long time; now I’ve been able to cross that off!  My wife has carried a smartphone for a few years now, so whenever we went on a trip together, she had mapping covered. 

The few times a year I would go on a long trip alone, though, I would be obliged to do things as we did it back in the olden days: To print a hard copy of directions off the Internet ahead of time.  (It’s certainly odd that we’ve reached a point where the phrases “back in the olden days” and “the Internet” can legitimately be used together in the same thought!)

Unlimited Calling

I previously avoided using my prepaid mobile phone for phone calls lasting more than a couple of minutes, since with my prepaid plan I only got a very small allotment of minutes per month; I’d use my home or office phone instead.  Now, though, I no longer have to worry about using up minutes, so I have the freedom to use the mobile phone for longer calls.

Pants Pockets

For years, I’ve walked around everywhere on a daily basis with my pants pockets pretty full of stuff: At first a Moleskine notebook, and later the iPod Touch, in my left pocket; phone and keys and mini-pen in my right pocket.  Now, with the single iPhone serving as both note-taking device and phone in my left pocket, I no longer need to stuff the dumbphone into my right pocket along with my keys.  Luxurious!

Vibration Alerting

The iPod Touch 5th gen. didn’t have a vibration feature, so now I can be alerted to new incoming messages even when my phone is on silent mode and in my pocket.

Firewall Circumvention Device (!)

My office has a long-standing policy of no use of streaming music sites permitted on the company network.  I’ve been somewhat envious for a while now of smartphone owners sitting near me who were able to use their phone’s data capability to listen to streaming music over the Internet, while I was limited to only my collection of mp3s on my local PC.  Now, I too am able to enjoy the variety of listening to Pandora while at my desk!  However, that does bring us to…


Bandwidth Cap

I decided to go with Verizon as the carrier for my new iPhone for several reasons: (1) They allowed me to transfer my accumulated Alltel/Verizon prepaid account balance of $100+ as a credit on the new smartphone bill; (2) I get a corporate discount on Verizon services; (3) My wife is already on Verizon, I didn’t really want to have her switch, and it was cheaper to have us both on the same carrier.

However, Verizon does impose a bandwidth cap on data usage.  For the first time, I am having to consider questions such as just how much data does it use to stream Pandora for 8 hours?

Form Factor

The iPod Touch 5th gen. is very thin – even thinner than the iPhone.  More than once, I had the slim iPod out and had someone notice the minimal width of the device and ask “What kind of phone is that?!” (I’d been tempted to answer that it was a prototype next-generation iPhone – mostly due to the irony that the device in question was actually less capable than a current-gen iPhone!)

In practice, though, I’m finding that the additional bulkiness of the iPhone isn’t something I really notice, as compared to the iPod Touch.

Monthly Fee

The biggest con, obviously is that the substantial monthly cost of the iPhone (even when subsidized) doesn’t exactly compare favorably with the $0/month cost of the iPod Touch.  After I’ve had the chance to use the iPhone for a longer period, I may do a follow-up on this post to comment on whether the advantages of the iPhone relative to the old iPod + dumbphone solution seem to have been worth the price.