Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. How to make simple code complicated

How to make simple code complicated

Scheduled Pinned Locked Moved The Lounge
csharpdatabasecomperformancetutorial
26 Posts 20 Posters 4 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • realJSOPR realJSOP

    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

    A Offline
    A Offline
    AFell2
    wrote on last edited by
    #21

    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.

    1 Reply Last reply
    0
    • L Lost User

      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 shit.) - 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 ->)

      D Offline
      D Offline
      Dean Roddey
      wrote on last edited by
      #22

      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

      1 Reply Last reply
      0
      • S Super Lloyd

        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)) { // do it! } } } 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) { // do it! } } } And there is much much more of it... :(( Well I guess that's why they pay me! :laugh: :^)

        A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!

        M Offline
        M Offline
        Member 9167057
        wrote on last edited by
        #23

        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.

        1 Reply Last reply
        0
        • S Super Lloyd

          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)) { // do it! } } } 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) { // do it! } } } And there is much much more of it... :(( Well I guess that's why they pay me! :laugh: :^)

          A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!

          U Offline
          U Offline
          User 13374275
          wrote on last edited by
          #24

          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.

          1 Reply Last reply
          0
          • S Super Lloyd

            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)) { // do it! } } } 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) { // do it! } } } And there is much much more of it... :(( Well I guess that's why they pay me! :laugh: :^)

            A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!

            D Offline
            D Offline
            David MacLean
            wrote on last edited by
            #25

            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 t

            1 Reply Last reply
            0
            • S Super Lloyd

              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)) { // do it! } } } 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) { // do it! } } } And there is much much more of it... :(( Well I guess that's why they pay me! :laugh: :^)

              A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!

              J Offline
              J Offline
              jschell
              wrote on last edited by
              #26

              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.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups