Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,150,366 members, 7,808,278 topics. Date: Thursday, 25 April 2024 at 09:45 AM

How Do U Program? Debug As U Code Or Debug After Coding? Which Is Best? - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / How Do U Program? Debug As U Code Or Debug After Coding? Which Is Best? (1579 Views)

Help Debug This Java Code / Please Help Me To Test And Debug This GSM Number Extractor Logic / Assembly Language/debug Wahala (2) (3) (4)

(1) (Reply) (Go Down)

How Do U Program? Debug As U Code Or Debug After Coding? Which Is Best? by possicon: 2:48pm On Jun 11, 2011
I'm curious, I want to know which one drives efficiency the most. Am begining to think debugging as you code slows down coding but on the other hand it helps you detect error as you go on. How do you code and which one has worked best for you? tnx
Re: How Do U Program? Debug As U Code Or Debug After Coding? Which Is Best? by cocoon(m): 7:23pm On Jun 11, 2011
I think Debug as u code coupled with unit testing is better. Basically i use TDD. Its most efficient once u are familliar with unit testing.

1. Write a skeletal code

2. Unit test

3. Make the test pass

4. Refactor

5. Write Production code

6. Debug Production Code

7. Refactor


IF u are conversant with Agile,XP or Lean the process makes u to be most efficient
Re: How Do U Program? Debug As U Code Or Debug After Coding? Which Is Best? by Fayimora(m): 2:56am On Jun 12, 2011
Well i like the fact that a list is here above. Now when you say debug. Thats something very very big. Now depending on what you are developing, debug as you code and then do a final debug before testing.
Ok that might have sounded strange so am gonna explain better.

When you write 5 classes of code that are probably aggregated, debug your code and make sure you aint gat no errors. A test class might be helpful here. You do the same as you go on an then when you are done you do a full debug which would go along side with testing(a beta stage). In this stage, you have done all necessary coding and whatsoever that has to do with code, then you debug and test. Both as I said would go at the same time.

Now as you grow into it, you would realise that you don't have to test until the whole application is done. Of course that depends on how much practice you have put into it.

goodluck
Re: How Do U Program? Debug As U Code Or Debug After Coding? Which Is Best? by candylips(m): 12:19pm On Jun 13, 2011
TDD is very effective
Re: How Do U Program? Debug As U Code Or Debug After Coding? Which Is Best? by possicon: 12:57pm On Jun 13, 2011
Thank you guys nice insights. I have been thinking along this particular line and having seen you suggest here is my likely decision;

1. Design; Architectural design of the software on paper mostly. Drawing on PC slows me down and sways me easily.
2. Algorithm; I'll attempt to solve the problem algorithmically, on paper or PC.
3. Coding: complete coding a particular algorithm
4. Unit test: I could test per page or a module then debug. I'm still thinking of debugging as I code if it's a framework/API am not quite familiar with. what do you think?
Re: How Do U Program? Debug As U Code Or Debug After Coding? Which Is Best? by cocoon(m): 4:41pm On Jun 13, 2011
A good design is the bedrock of a successful program, i mean the architecture.
U can design on paper but u there are some nice design tools online
SketchFlow is a good tool ,part of Expression Studio


But there are other things involved.

U need to understand some certain principles.

A good software needs to have some principles called SOLID

Single responsibility principle

Open/closed principle

Liskov substitution principle

Interface segregation principle

Dependency inversion principle


U can read them up online

It depends on what type of app u are developing

Desktop - MVP
Web - MVC
Silverlight/ WPF - MVVM

U could use any pattern for any app ,but these are tested and mostly prefered patterns.

Test Driven Development -Test first before coding

There is white box testing and Black Box testing

U do white box testing before ur production code -- Unit Testing (see my first post earlier)

When u unit test , u break each component of ur app into units or bits and isolate each one and test seperately without any dependency

e.g in ur data access layer (DAL) , u have an interface IDatabaseTasks

using System
namespace DbAccess
{
public IDatabaseTasks
{
//Method for adding a record
int AddUser(User user);

//Method for Updating a record
int UpdateUser(User user);

//Method for Deleting

int DeleteUser(int userId);
}

}


Then Create the concrete Class

public class DatabaseTasks:IDatabaseTasks
{
public string UserName{get;set;}

public DatabaseTasks()
{
}

int AddUser(User user)
{
}

int UpdateUser(User user)
{

}

int DeleteUser(int userId)
{
}

public override ToString()
{
return UserName.ToString();
}
}


In order to tested each method effectively without connecting to any database.

U will have to do a unit test. Test each method. Isolate each method

Create a test project. Each programming language has a testing api
Java - junit
.net - Ms Unit,Nunit,RhinoMock
php - Phpunit
Jquery,JavaScript - FuncUnit
Sql (StoreProcedures, Triggers,View) - SqlUnit or DatabasetUnit in Visual Studio

The mocking Framowork will implement the interface automatically for u

e.g.
using Nunit;
using RhinoMock;

public class DatabaseTasks.Tests
{
var mockDatabaseTasks=MockRepository.GenerateMock<IDatabaseTasks>();

[TestFixture]
public void AddUser_AddANewUser_ReturnNumberGreaterThanOne()
{
}

[TestFixture]
public void AddUser_DontAddANewUser_ReturnNumberLessThanOne()
{
}



}

Even if u are using netbeans u can download some other testing frameworks (i think junit came with netbeans )
Pass ur tests

Then go back to the Class DatabaseTasks and write the implemtation (Production code).
Debug
Refactor

Write another class
Follow the same procedure

once u are tru. u can do an integrated testing where u need to connect to a database
Re: How Do U Program? Debug As U Code Or Debug After Coding? Which Is Best? by possicon: 9:34pm On Jun 13, 2011
Nice boss. I will follow the steps. Though I develop for mobile more these days.

(1) (Reply)

[php Tutorial] - Building A Rest Api / How Did You Get Into Tech?(what Motivated You, Downfalls, What Discourage You) / As A Techie What State Do You Live And How Is Electricity In Your Area

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 19
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.