Welcome Guest, Not a member yet? Register   Sign In
save and edit share same method?
#5

"a method should do one thing and do it well". its very tempting to create very long methods like you are doing that do many different tasks. the problem is that this is basically exactly the same as procedural programming. why is this an issue? because you end up with "spaghetti code" that is very difficult to maintain.

you are thinking - oh hey i'm making one method to take care of different conditions this is very smart and efficient right? no - its not efficient because in your code you are constantly having to ask questions like - is this new? is this an edit? is this valid? what is my name again?

the longer the method - the more time it takes to debug. because you are typically having to sift through a bunch of conditions. short methods that do one thing - its very fast to find the issue or to update them.

the key is to build like you are doing - but then refactor into smaller methods. at first this might seem like its 'more code' but it ends up being much cleaner and easier and faster to work with. for example put the validation in its own method - it then returns either true or false. if false you show the form again. the validation method does not need to know if this a new insert or an edit.
Reply


Messages In This Thread
save and edit share same method? - by iridion2015 - 05-05-2016, 08:40 PM
RE: save and edit share same method? - by cartalot - 05-06-2016, 12:05 PM



Theme © iAndrew 2016 - Forum software by © MyBB