|
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.
|
|
|
|
|
It can also make testing easier with more separation. Logic embedded in a loop can sometimes be tricky to test on single items. You might be able to make very small lists but not always.
"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?"
|
|
|
|
|
I recently replaced two nested loops with index arithmetic with a single function call. I even have a theory of why this old code was in place, but I feel still dumbfounded by spending several minutes deciphering what the code is supposed to do while, really, a single call to a single well-documented function would have done the job.
|
|
|
|
|
Each code contains at least a useless line and a wrong one.
So... do { Remove(code.WrongLine); } until (code.NumberOfLines == 1)
You obtain a code with a single line: a useless and probably wrong line.
|
|
|
|
|
We all admit that this happens, but we never stop to think about why it happens. Let me put forth a hypothesis - deadlineitis!
Programmers have been bamboozled into believing that software development should be an engineering discipline. While there are some things that engineering can offer to software development, there is much that the engineering discipline cannot "solve" for software development.
Let me defend this. "Engineering" is the discipline that says we can build massive structures by applying known smaller structures, that have mathematical descriptions which can be added together to present a mathematical model of the desired structure.
In software development, so-called "software engineers" repeatedly encounter instances of where there is NO smaller software structure - merely methods that "almost" work, methods which are "not quite" what is required, or even a lack of smaller structures that even come close to what is required. Add to this that combining all these "iffy" structures together leads to coupling problems - emergent behavior unanticipated by anybody. (And if you are looking for mathematical precision, well, good luck with that.) So software development winds up being a series of "experiments" - tweaking prior structures, and even developing your own structures, with the "requirements" for the structures being imprecise and unclear.
Under "project management", this is seldom, if ever, accounted for, because, like so much other stuff, the concept of "project management" was imported into the domain of software development from the engineering disciplines.
Imagine, if you will, the plight of an bridge engineer if he had to redefine what a "truss" was multiple times during the life of the project.
It's relatively easy to put together a bunch of well-known structures to complete a much larger structure on time, on budget, and safe (yet even then we have major cost overruns and major delays, and even failures of the final product).
The problem with software is the fact that compared to "physical" products, there is no conceptual limit to what an individual piece of software might be. You want it to do A, B and C. Why not? Could you get it to do D as well? No problem. How about E and F? Well, that may strain our resources a bit. Oh, we can't have that. How about if we eliminate C and D - could we get E and F for the same cost and in the same time?
And on and on it goes. So what happens when a software developer has to develop on of these base widgets, or tweak another. The programmer does not have a mathematical model to rely on, but just a natural language description of what has to be done. This is, of course, ambiguous, and the first kick at the cat fails. Two choices - tweak, or total rewrite. Over the course of development of this one widget, total rewrite is an option at the start, but hardly one over the course of time. And the deadline is looming. (Deadlines ALWAYS loom.) So it comes down to tweaking. Finally, unit testing succeeds. Hallelujah. You know that you should go back and refactor, and tighten up the code, but you're scheduled to work on another widget, so you start on that while the widget you've completed sits in the integration testing queue.
And just when you are deeply into the next widget, you are hauled away because your widget failed integration testing. You are already behind on that other widget, so you get all the information you can on how this widget failed integration testing, and you tweak the code, and unit test it, and put it back into the integration testing and you go back to that other widget, and on, and on, and on, and on.
And finally, after all developers have collectively torn their hair out by the roots, have lost an average of 20 pounds because "there's no time to eat", do not remember when it was the last time they sat down with their significant others, and have bloodshot eyes from putting in 18 to 20 hour days for the last of the project, QA says that they approve for release.
And six months from now, some new hire in maintenance is calling you up on the phone complaining that your code is too complex!
It is to weep.
|
|
|
|
|
Super Lloyd wrote: And I knew I was right, it's not just me, code was complicated!
If the idiom was consistent then there probably was a reason.
Some reasonable possibilities for indirection (which might not apply in your case)
- Unit testing mocking
- Insuring that the current db code does not leak into other layers.
|
|
|
|
|
Though I've open sourced a butt-load of code, the current trends that I see around open source are not good. I see all these people screaming about how great open source is and how it's stupid to be proprietary these days and how companies are finally waking up and becoming more consumer-centric.
But that's exactly the opposite of what is happening. All of this is part of an inevitable move to copy Google's example. They have worked out a system where they make massive amounts of money off of us, but without having any obligations to us, because they don't sell us stuff, they sell us.
That has created a world where all the other big companies are going the same direction. Stop being a company that makes software to sell, and become a company that gives away software as a gateway drug to getting customers addicted to their cloud based services. The inevitable end of that road takes us back to the 60s, with a huge, air conditioned machine that we have to rent time on.
If you don't sell the software itself then you make your money by spying on users and selling the data, by charging rent to use your software, or by pushing ads. Are any of those scenarios actually better for us as customers? It ultimately means that they have no more obligation to you than the end of the month. They can cut you off any time, or drop any product, and you have no foot to stand on because you never bought it.
And of course it'll go meta as well, where you'll be renting software from people who are renting cloud based services from larger companies that they use in the software they rent to you. If large companies can create features that everyone feels they need in order to be competitive, and they can keep that competitive level so compute intensive and complex that it can't reasonably be replicated for local use, then folks will use those cloud based service in their own software because they feel like they have to.
Speech recognition is a good current example. My CQC automation system has an all local voice control system, but it really can't compete with the Echo, which uses state of the art DNN technologies backed by massive amounts of training data and computing resources. So we also have to support the Echo to be competitive. And the odds aren't great this will change.
Speech Recognition and Voice Control[^]
As these companies become enormously profitable not selling software, they are sucking up massive numbers of top engineers to help them make that cycle go faster. And they are sucking up massive numbers of top engineers, with salaries and benefits that others can't compete with. Even if you have some lingering doubts about what these companies are creating long term, it's very hard to turn down the pay.
Anyway, I'm obviously not against open source per se, having open sourced more of it than your average 100 other developers combined. But I just think that there's a lot of naivete out there about all of this and why companies like Google open source so much code. It's not largess, it's long term strategy.
Explorans limites defectum
modified 23-May-19 14:31pm.
|
|
|
|
|
Not bad at all
It does not solve my Problem, but it answers my question
modified 19-Jan-21 21:04pm.
|
|
|
|
|
Dean Roddey wrote: Stop being a company that makes software to sell, and become a company that gives away software as a gateway drug to getting customers addicted to their cloud based services. Great idea !
«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
|
|
|
|
|
Of course there's naivete out there, way too much of it. Spoke with several people myself about topics such as open source software, bitcoin (or cryptocurrency in general) and similar stuff. My main conclusion is that people tend to fall in love with the idea, with the ideals behind the idea, and completely ignore such puny details as real-world ramifications. When kids commit that mistake, it's cute. In case of adults though, it quickly gets awkward.
|
|
|
|
|
Forget about the other stuff I want to see that Close-Quarter-Combat automation system.
|
|
|
|
|
In retrospect the name was maybe not a good choice. It's short for Charmed Quark Controller, but always gets shortened to CQC. If you search for CQC though, in addition to closer quarters combat, you get all kinds of stuff. Camden Chess Club, Care Quality Commission, California Quality Collaborative, China Compulsory Certification, Community Quality Council, Canadian Quilting Club, and on and on.
Explorans limites defectum
|
|
|
|
|
I think you missed the point. Google has never ever sold software. They are a services company. The same can be said of Facebook. And there are plenty of companies selling software AND contributing to open source. The two are not related at all.
What I do see is that more and more companies are releasing the portions of the software not directly tied to their business. Facebook has released Bootstrap and React as an example. Both projects help them closer to their goal. Neither is the core product.
Now there is also a movement toward selling the data gleaned from providing "free" software as well. And on phones some have found they make far more from the advertising then they can make from selling ad free. But the two issues are separate.
|
|
|
|
|