Welcome to Dream.In.Code
Getting Help is Easy!

Join 136,109 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,722 people online right now. Registration is fast and FREE... Join Now!




Optimizing Code Vs. Ease of Use

 
Reply to this topicStart new topic

Optimizing Code Vs. Ease of Use

snoj
30 Oct, 2007 - 07:56 AM
Post #1

$Null
Group Icon

Joined: 31 Mar, 2003
Posts: 3,304



Thanked: 6 times
Dream Kudos: 700
My Contributions
One of the things I'm running into while working on DIC's Code Snippets is execution speed verses easy to use code.

For instance, when getting details on a snippet, it's easier to just return all the data on the snippet so it's there when I pass it to the template system. Also, it means the designer can come along and present the data however they need to. However, this doesn't lend to a "fast" application though since I'm moving around what can and is vast amounts of data that may not be used.

Another thing I've run into is calculating data on the fly. That is, calculating things like ratings instead of calculating and storing that data statically. I find in small settings this isn't a terribly big deal, however with the size of DIC and the Code Snippets, I've had to change how I do/did things.

So I pose this question, which do you prefer to use and why?
User is offlineProfile CardPM
+Quote Post

orcasquall
RE: Optimizing Code Vs. Ease Of Use
30 Oct, 2007 - 08:12 AM
Post #2

D.I.C Head
Group Icon

Joined: 14 Sep, 2007
Posts: 158



Thanked: 3 times
Dream Kudos: 50
My Contributions
Ease of use first. I optimise my code on the fly as I'm coding, but I don't give it too much attention first. I need to get it working, before thinking about making it work more efficiently. I'm actually more worried the next programmer don't understand what I just wrote...

I found the optimisations I do make usually involve algorithmic or logic changes. The (increasingly better) hardware took care of the minor stuff I left out.
User is offlineProfile CardPM
+Quote Post

tody4me
RE: Optimizing Code Vs. Ease Of Use
30 Oct, 2007 - 08:55 AM
Post #3

Only Jenny Craig makes thin clients...
Group Icon

Joined: 12 Apr, 2006
Posts: 1,278



Thanked: 3 times
Dream Kudos: 100
My Contributions
I try to use speed in code as opposed to readability because I don't normally have to go back in and add things. It's always been just me looking at the code. While I realize that's not the norm, I do go back and clean up the code and do commenting after the fact. Then the users can use the program, and don't notice a real difference when I make the changes to the versions.
User is offlineProfile CardPM
+Quote Post

Amadeus
RE: Optimizing Code Vs. Ease Of Use
30 Oct, 2007 - 09:00 AM
Post #4

g++ -o drink whiskey.cpp
Group Icon

Joined: 12 Jul, 2002
Posts: 12,226



Thanked: 37 times
Dream Kudos: 25
My Contributions
What about if you are no longer the developer? If others need to read the code?

I try to approach it from both angles. Obviously, there are some common optimizations that can be taken into account pre-programming (especially if you follow proper development procedures and have a detailed design document), but others that will have to be implemented post programming once the performance has been measured. For those optimizations, I'll do those AFTER my code has been written in a readable state.

As for calculations, I try to leverage whatever can be done by the data source (a db usually) to try and end up with my calculations already done by the query. When that's not possible (and it has to be done in code), I try to shuffle massive calculations off to parallel processes.
User is offlineProfile CardPM
+Quote Post

PsychoCoder
RE: Optimizing Code Vs. Ease Of Use
30 Oct, 2007 - 09:19 AM
Post #5

using DIC.Core;
Group Icon

Joined: 26 Jul, 2007
Posts: 8,983



Thanked: 125 times
Dream Kudos: 8600
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions
My main focus is optimization, I use enough comments in my code to thoroughly understand what it's doing. We have a database with well over 10,000,000 records in it, and we applications being hit 50,000 - 100,000+ times a day (now multiply that by 8 web applications), and within the last year we've had over 120,000 new delegates added to the system so optimization is extremely important to my company.

Don't get me wrong, I don't write cryptic code, but with each line of code I write I have to ensure it's going to run as fast and efficiently as humanly possible. Like Amadeus, I do all my calculations on the database end whenever possible, otherwise Ill run complex calculations in their own thread so the application doesn't have to wait for that to complete before moving on. The trick with that is to ensure I dont need the results of the calculations before that process is complete, been there done that.

In the end, before releasing into production, I do my best to find a nice mix of both when possible, but for me optimization will always come first, I can always add more comments to make following it easier for the next developer.

This post has been edited by PsychoCoder: 30 Oct, 2007 - 09:30 AM
User is online!Profile CardPM
+Quote Post

ahmad_511
RE: Optimizing Code Vs. Ease Of Use
31 Oct, 2007 - 12:28 PM
Post #6

D.I.C Regular
Group Icon

Joined: 28 Apr, 2007
Posts: 351



Thanked: 8 times
Dream Kudos: 400
My Contributions
When I start coding something, I actually try to make it simple and easy to use as possible as I can.
Ok, I have to confess something, before I contribute for DIC site; I was too messy when writing codes.
I don't know why I have to comment the code, in my view that was a big wasting of time.
And I was writing lines which are very long and difficult to read.
But actually it works good.
And that was my bad, when other friends tried to read my code; they had to separate the lines from each other and wasting more time to understand it.
After I subscribed to DIC, I used to write more comments even if it's not necessary to me.

I always try to write the smallest script and free of logical errors as possible, but not if that will affect the efficient speed of progress.
To me, the simple of use came first.

User is offlineProfile CardPM
+Quote Post

baavgai
RE: Optimizing Code Vs. Ease Of Use
31 Oct, 2007 - 03:58 PM
Post #7

Dreaming Coder
Group Icon

Joined: 16 Oct, 2007
Posts: 2,019



Thanked: 105 times
Dream Kudos: 475
Expert In: C, C++, Java, C#, ASP.NET, PHP, Perl, Python, Oracle, SQL Server, MySql, HTML, JavaScript, Lua

My Contributions
"Optimizing Code Vs. Ease of Use." Without being too obnoxious about it, I'd have to say they're the same thing.

When writing code there's a lot of cut and paste and generally ugly stuff. Code that "finally works" is first draft, warts and all, not fit for others to see. However, that's when the real fun begins; refactoring.

Taking the unruly mess and grooming it. Making methods or functions where redundant code is found. Getting rid of things like "select *". Adding bind variables, defining constants. Removing old code that's no longer used and trimming functional code to make it leaner.

This process of refactoring inevitably leads to a kind of optimization and can often divulge potential bugs. The goal of the process is "ease of use" in the form of ease of maintenance. It creates code that ideally has one, and only one, place to go to fix a point of failure or make a global change.

User is offlineProfile CardPM
+Quote Post

spullen
RE: Optimizing Code Vs. Ease Of Use
1 Nov, 2007 - 03:56 PM
Post #8

D.I.C Regular
Group Icon

Joined: 22 Mar, 2007
Posts: 330



Thanked: 1 times
Dream Kudos: 50
My Contributions
I would definitely make the code make the code easy to use, while thinking about optimization. Like just try to make it so later on it is easier to optimize the program's code.
User is offlineProfile CardPM
+Quote Post

RodgerB
RE: Optimizing Code Vs. Ease Of Use
2 Nov, 2007 - 06:19 PM
Post #9

D.I.C Lover
Group Icon

Joined: 21 Sep, 2007
Posts: 2,131



Thanked: 16 times
Dream Kudos: 2200
Expert In: Dot Net Technologies

My Contributions
It certainly depends on what approach you have and your goal.

If you are working in a team:
  1. Ease Of Use - So others are able to pickup from where you left, and make everyone's life easier.
  2. Optimizing Code - As this can be achieved as a collaborative task and/or discussion.

If you are working by yourself:
  1. Optimizing Code - Because you only have yourself to blame if it's slow.
  2. Ease of Use - Because if it's closed source only you have to understand it.


This post has been edited by RodgerB: 2 Nov, 2007 - 06:20 PM
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/1/08 09:34PM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month