|
A clue for his mini CCC, moustache sounds like a nag about my posting time (6)
We can’t stop here, this is bat country - Hunter S Thompson RIP
|
|
|
|
|
With seconds to lose, Agnes backs winner for toaster (9)
|
|
|
|
|
With seconds to lose, (remove "S")
Agnes AGNE
backs winner CHAMP
for toaster
CHAMPAGNE
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Yup
|
|
|
|
|
At first glance real application (new) code from someone else always looks complicated, and one has to work with it for a while to find it, eventually, simpler. And sometimes I wonder if with old age and worst memory I suffer from that more.
Yesterday I mentioned some code looks excessively complicated for no reason, i.e. it does very simple task, and I got an incredulous look from a fellow developer... Maybe I was wrong?
First I am always confused by the double layer of obfuscation where getting something from the db goes through 2 pass-through layers, each hidden behind their own interface, that return "data model". Thanks god for Go To implementation and also sometimes some property are not named like the columns, or swapped around, tricky...
I guess I am getting old here..
But then I stumbled on that (code simplified for sake of "clarity")!
And I knew I was right, it's not just me, code was complicated!
void DoSomething()
{
foreach (var d in Data)
{
if (MustDo(d.Code))
{
}
}
}
bool MustDo(string code)
{
if (BigCondition)
{
return GetData(code)?.Should ?? false;
}
return false;
}
AData GetData(string code) => Data.FirstOrDefault(x => x.Code == code);
clearly this is over complicated and can be rewritten
void DoSomething()
{
foreach (var d in Data)
{
if (BigCondition && d.Should)
{
}
}
}
And there is much much more of it...
Well I guess that's why they pay me!
modified 23-May-19 21:41pm.
|
|
|
|
|
I do notice how everyone else's code is over-complicated, outdated, and needs re-writing
«Where is the Life we have lost in living? Where is the wisdom we have lost in knowledge? Where is the knowledge we have lost in information?» T. S. Elliot
|
|
|
|
|
You too, hey!?!
|
|
|
|
|
I often note that my own code is outdated, overcomplicated and needing rewriting.
|
|
|
|
|
I do like looking at my clean, simple, maintainable code.... but then I have to move on, and as I press the enter key I add yet another line of code to the maintenance nightmare.
|
|
|
|
|
It takes longer... but it still happens occasionally.. mostly because I do thing completely differently later...
|
|
|
|
|
Being paid per line of code has all sorts of ramifications.
|
|
|
|
|
You're missing the Code==code check part. But yes, it does look like it's overly complicated and can be simplified.
|
|
|
|
|
I am not!
We got an item from a list.
We pass the id (aka code) of the object to another method
the other method use the id to lookup the (original) item from the list
I can simplify by directly using the original item
|
|
|
|
|
That requires some knowledge of the domain - the fact that Code is unique within the list. If that wasn't the case, then your simplification would have subtly changed the behaviour.
Edit: As already pointed out below[^].
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Super Lloyd wrote: And there is much much more of it...
apart from adding layers of "really useful" stuff another favorite weenie passtime is implementing the very latest language features regardless if it makes sense useful or not. Even if doing so they manage not to not break the code they do ensure it becomes incompatible with people using older versions of the dev platform.
shitloads of unmoderated stuff on github is constantly "updated" to use the very latest features of c# (or whatever language), and it's just too bloody bad for people using that if they are still on vs2015 or earlier.
like idiot kiddies that feel a strong need to mount a wing on their car, 75% of the time it does nothing because their POS car is too useless to have it matter, and 24.9% of the time it'll actually reduce / retard safety and performance.
my rules for using open/other peoples code/source/hell other peoples anything:
- always copy and use local version only. (reference/acknowledge the origin in comments only)
- if/when possible/time replace it with own code ... (other peoples code is always sh*t.)
- only ever update if there is a very strong reason ... (small problems fix it yourself).
- don't use just because it's there and looks cool. ... (today's cool is tomorrows dog vomit.)
Why? Well delivering applications, packages and even complete systems to clients:
- stability is 1,000 times more important than being the latest thing out there.
... and that saves me a shitload of 3AM Friday night headaches I don't need
Message Signature
(Click to edit ->)
|
|
|
|
|
Lopatir wrote: like idiot kiddies that feel a strong need to mount a wing on their car
Great analogy!
"Go forth into the source" - Neal Morse
|
|
|
|
|
I have noticed that most of those wings go on front-wheel drive cars and a wing on the rear end doesn't help those a whole lot and they don't help any car at lower speeds ie., the vast majority of driving.
This reinforces your point even more - the added accessories might look nice but are of very little real value.
"They have a consciousness, they have a life, they have a soul! Damn you! Let the rabbits wear glasses! Save our brothers! Can I get an amen?"
|
|
|
|
|
Come to the C++ world and really experience the love. Some 'post-modern' C++ doesn't even look like C++, because it sort of isn't. It's really Templates with C.
Explorans limites defectum
|
|
|
|
|
Well, technically your version is slightly different. If there are more then one item in Data with a given Code then the original version will (probably buggy) use the first one to determine .Should.
So, your point is well proved. Better performance (O(n), as opposed to O(n^2)) and bug free. Easier to read and maintain.
|
|
|
|
|
if (BigCondition) should be moved outside the loop though.
Wout
|
|
|
|
|
Does any other code call the MustDo method?
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
I see two reasons to make the MustDo logic its own function:
#1: It is used in more than one place (not visible in the example).
#2: Separating it improves the clarity of the logic in its original location.
My worst tendency in the code I write is to let individual functions get large. Logic can become nested too deeply and the code can run over several screenfuls. As I debug, I will then have to refactor and move nested bits and pieces into their own functions just to make the overall thing clearer. If the development pace is a little slower, I'll do the refactoring as I write.
Software Zen: delete this;
|
|
|
|
|
I try to put discrete code into its own method where it makes sense, even if the code isn't called anywhere else. In the event that the code is specific to a class, and not called from anyplace else in the app, I make it private or protected (depending on its purpose). This pretty much keeps most methods to less than 50-100 lines.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
The key for me is knowing when to stop. I had a coworker who was manic about writing his code in an OOP fashion. If he had a function with more than two control constructs (if , for , while ), he would often split it into multiple functions. While this may have been appropriate from an OOP-purist point of view, it could make logic and flow difficult to follow. It also made for a polluted name space. His names were good, but the fact that there was a name for something that was just an if statement obscured the significance of the function.
Software Zen: delete this;
|
|
|
|
|
Using access modifier internal is another way to be sure your method is never used outside of the assembly. For instance, I use it in static extension classes where I want to use an extension method anywhere in the library solution, but I don't want folks who use the library to have access to it.
|
|
|
|