|
You’re not wrong, but you’re also not necessarily right. Coding preferences should be agreed upon, codified, and automated to avoid debate. The important thing is that there’s consistency.
Calling a coding practice “lazy” (like the use of ‘var’) is condescending, at best, and smells of arrogance. It’s also associated with narrow-mindedness, and quite frankly, can date you in a bad way. I’m sure the intent was a call for action, but your reasoning and diction could be improved.
Very simply, the guidance on the use of ‘var’ states that it should be used only if the type is repeated or obvious (without IntelliSense) on the right side of the equals sign; this simultaneously makes it easier to spot variable declarations while respecting the intelligence of the reader, who may not really care what the type is up front, especially if the name is well-chosen or the type name is long. A similar logic can be applied, per your preference, for the implicit new() operator, though I tend to see those used mostly on field initializers. Having said that, the Framework Design Guidelines recommends *against* the use of var, except when using ‘new’, ‘as’, or a hard cast, in which cases it is *permissible*.
|
|
|
|
|
I would have done things this way:
private IMultipleComponentHandler SelectionHandler
{
get
{
if (m_selectionHandler == null)
{
if (SelectedObject is IMultipleComponentHandler handler)
{
m_selectionHandler = handler;
}
else
{
object[] collection;
if (SelectedObject is IEnumerable e
&& !SelectedObject.GetAttributes<IgnoreIEnumerableAttribute>().Any())
{
collection = e as object[] ?? e.Cast<object>().ToArray();
}
else if (SelectedObject != null)
{
collection = new[] { SelectedObject };
}
else
{
collection = Array.Empty<object>();
}
m_selectionHandler = new InspectorMultipleComponentHandler(collection);
}
}
return m_selectionHandler;
}
}
private IMultipleComponentHandler m_selectionHandler; I'm an old fart who prefers single-exit .
Software Zen: delete this;
|
|
|
|
|
I would be tempted to extract the contents of the if statement as a function, like this:
public IMultipleComponentHandler SelectionHandler
{
get
{
if (m_selectionHandler == null)
{
m_selectionHandler = InitialiseSelectionHandler(SelectedObject);
}
return m_selectionHandler;
}
}
private IMultipleComponentHandler InitialiseSelectionHandler(object selectedObject)
{
if (selectedObject is IMultipleComponentHandler handler)
return m_selectionHandler = handler;
object[] collection;
if (selectedObject is IEnumerable e
&& !selectedObject.GetAttributes<IgnoreIEnumerableAttribute>().Any())
{
collection = e as object[] ?? e.Cast<object>().ToArray();
}
else if (selectedObject != null)
{
collection = new[] { selectedObject };
}
else
{
collection = Array.Empty<object>();
}
return new InspectorMultipleComponentHandler(collection);
}
private IMultipleComponentHandler m_selectionHandler;
This hides the issue of using a temporary variable, snapshots the SelectedObject so the value being used can not change while updating the handler and the getter property for SelectionHandler becomes easier to read.
An added bonus is if SelectedObject changes you can update the handler by calling InitialiseSelectionHandler.
|
|
|
|
|
This is way cleaner..
It is a sort of lazy initialization.. and usually it is split exactly that way: a backing field, a property that lazily initializes the field, and a method that performs the initialization.
This also highlight a possible race condition after the very first null check, that can be avoided by a double-checked locking inside the property get accessor; and the InitialiseSelectionHandler method would remain untouched.
I'd just keep the backing field close to the property (I usually keep the field immediately before the property).
|
|
|
|
|
|
I was struck by a quote from an Insider News article Kent posted about some new DevOps developments: [^]:
"The cusp of maturation of previously bleeding-edge paradigms."
My head went fast-forward to 2025, where a developer named Devindra Codearaja has just received a reply/warning from his Dev-Ops team's "Substance Enhancement" committee ... I quote:Quote: Dear Valued Team Member, Devindra,
We have evaluated your request to increase your daily methamphetamines allowance, and, given the results of your most recent blood-screening profile, we must say, in the interests of the Team, we cannot grant that request.
We have detected trace amounts of MDMA aka "Ecstasy" [^] in your blood; as you know, MDMA is not an approved substance for your Team.
It is in the interests of the Team to avoid excessive empathy, and distracting personal insights, or inappropriate bonding behavior: all of which are associated with this drug.
Since your work is excellent, and your behavior in SCRUM slug-fests is appropriate, we will take no punitive action at this time.
However, per your contract, your supplementation will be modified to include:
1) daily: 5 mg. of Xanax given orally
2) 1x weekly: LSD 25 micro-grams to be given orally 2hrs. before Friday SCRUM.
Do be aware that if the next screening shows any signs of unauthorized drugs ... or indicates you have not taken your approved supplements ... further action may be required.
Please schedule a private session with our substance-counsellor bot.
Sincerely, Edwina Hawkins,
Substance Enhancement Committee
«The mind is not a vessel to be filled but a fire to be kindled» Plutarch
|
|
|
|
|
Or maybe I'm just getting paranoid.
singing
Liars, Vipers, Jokers and Fakes: we have a man in a room with a photograph of you and a very long list
we really get around everybody is written down, nobody ever gets missed
we know you through and through - know more about you than you know about yourself
we got a magical machine that has every word you speak and can write it all down
so you better watch your mouth or we'll come knock on your door.
we are the liars and vipers and jokers and fakes everywhere you go
the liars and vipers and jokers and fakes on your radio
we are the liars and vipers and jokers and fakes in the driver's seat
we are the liars and vipers and the clowns at the wheels of history
WHITEY - LIARS, VIPERS, JOKERS & FAKES (OFFICIAL AUDIO) - YouTube[^]
I'm not sure if how I feel is because of the encroaching surveillance state coming to us live by way of well... you and me when it comes down to it, or whether it's because of the general political landscape in the west, or what. This song gets to me.
Real programmers use butterflies
|
|
|
|
|
|
YIKES!
Nickelback was a psyop campaign by Canada intended to weaken the US, and they should face sanctions over it.
Real programmers use butterflies
|
|
|
|
|
Don't worry, the reptilian underground overlords are onto it!
|
|
|
|
|
... I've just flown back to Australia after nearly 2 years locked out. I'm here, but so is Omicron, so as I was travelling the borders again shut down and instead of being in the Melbourne office safe and sound, I'm locked up in a hotel in Sydney with a warning that if I leave the room the Police get called.
Hopefully sanity prevails and I can continue to Melbourne in 3 days, but unfortunately the last 36hrs have been a bit of an unwelcome adventure and the survey was pushed down the stack (somewhere above "have a shower", but below "work out how to get food and water given the hotel restaurant is shut and I can't leave the room")
So I'm opening this one to the floor: Who has a good survey question (and answer options!). Come in, Spinner...
cheers
Chris Maunder
|
|
|
|
|
I don't think you're allowed hints from the peanut gallery or a "phone-a-friend" when doing one of those locked-room challenge thingies.
|
|
|
|
|
Computer guy is told he's to be locked inside a hotel room for 72hrs
Computer guy looks at recently stocked mini fridge, coffee maker, laptop, chargers and phone.
Computer guy goes back to coding.
cheers
Chris Maunder
|
|
|
|
|
I've had one rattling round the back of my head for a while. I'll email it to chris@cp.
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012
|
|
|
|
|
Chris Maunder wrote: Who has a good survey question (and answer options!).
Here's one:
How will Chris get food and water?
Pick one:
A: Take out delivered by a taxi to the hotel room door
B: Raiding the mini-bar in his hotel room (assuming there is one and it's not already raided.)
C: Sneaks out at 2 AM with an appropriate disguise
D: Air-dropped by the Code Project Air Force Rescue
E: Starves
|
|
|
|
|
Marc Clifton wrote: D: Air-dropped by the Code Project Air Force Rescue
Interesting, I did not know we had something like that. Where can I apply? I like flying with helicopters and I also have training and experience. Still, we might reserve firing a Patriot at him as a last resort.
I have lived with several Zen masters - all of them were cats.
His last invention was an evil Lasagna. It didn't kill anyone, and it actually tasted pretty good.
|
|
|
|
|
Hey! I can hear you guys!
cheers
Chris Maunder
|
|
|
|
|
That's literally what's been in my head all day. Word for word.
I've finally got it sorted though. No minibar, but there is Jimmy Brings. And it works. I tested.
cheers
Chris Maunder
|
|
|
|
|
Chris Maunder wrote: Who has a good survey question Which function design pattern do you prefer?
[ ] Bouncer Pattern
[ ] Fail Fast
[ ] Guard Clause
[ ] Happy Path
[✓] Single Entry/Exit
Probably a few more I've never heard of. Maybe the others can chime in.
|
|
|
|
|
[] Right tool for the right job
|
|
|
|
|
What's the difference between guard clause and bouncer pattern?
|
|
|
|
|
And the answer is "because Australia has become a totalitarian State.?
|
|
|
|
|
Trying not to start the soapbox, but ...
From what I've seen in the your media, our situation has totally been misrepresented. I'm thinking in particular of one of your politicians calling for Australia to be invaded to free us - please don't.
Here in Queensland we had the big lockdown last year and a few smaller ones since. Other than that we are free to go out for dinner, movies, have weddings (my daughter got married this year), go to sporting events, etc etc. At the moment masks are not mandatory (although I still wear it on the train).
Down south there've had it a bit rougher and have had higher numbers, but with high vaccination rates these restrictions are being lifted.
// TODO: Insert something here Top ten reasons why I'm lazy
1.
|
|
|
|
|
yacCarsten wrote: I'm thinking in particular of one of your politicians calling for Australia to be invaded to free us - please don't. IIRC - It was Candace Owens (a conservative media type not a politician) and she was being facetious, she even stated as much in the article preface. I certain rather large portion of US media that openly supports the opposite end of the political spectrum misrepresented her.
|
|
|
|
|
There's an election next year so let Australians decide what they think about it all, overall, instead of throwing out cheap labels. Every country has made their own decisions and there will be decades of post-doc theses full of 20/20 hindsight on who did what best.
cheers
Chris Maunder
|
|
|
|