What is a good practice to check if an environment variable exists or not?

Use the first; it directly tries to check if something is defined in environ. Though the second form works equally well, it’s lacking semantically since you get a value back if it exists and only use it for a comparison. You’re trying to see if something is present in environ, why would you get just … Read more

WPF Checkbox check IsChecked

You can use null coalescing operator. This operator returns right-hand operand if the left-hand operand is null. So you can return false when the CheckBox is in indeterminate state (when the value of IsChecked property is set to null): if (chkRevLoop.IsChecked ?? false) { }

Refactoring if/else logic

You should use Strategies, possibly implemented within an enum, e.g.: enum UserType { ADMIN() { public void doStuff() { // do stuff the Admin way } }, STUDENT { public void doStuff() { // do stuff the Student way } }; public abstract void doStuff(); } As the code structure within each outermost if branch … Read more

jQuery determine if ul has class OR another one

You could use is instead? if ($(‘#menu-item-49’).is(‘.current-menu-item, .current-menu-parent’)) { $(‘ul.sub-menu ‘).css(‘display’, ‘block’); } Check the current matched set of elements against a selector and return true if at least one of these elements matches the selector. Beats having to use multiple hasClass queries, which is the alternative: if ($(‘#menu-item-49’).hasClass(‘current-menu-item’) || $(‘#menu-item-49’).hasClass(‘current-menu-parent’)) { $(‘ul.sub-menu ‘).css(‘display’, ‘block’); … Read more