Clean Code

I was reading this book ” Prentice Hall Clean Code A Handbook of Agile Software Craftsmanship ” and its really very useful. I recommend you to read it.

Some sentences and phrases that I liked. 🙂

Writing clean code is what you must do in order to call yourself a professional.

There is no reasonable excuse for doing anything less than your best.

“Honesty in small things is not a small thing.”

In our profession, we desperately need all the help we can get. If a clean shop floor reduces accidents, and well-organized shop tools increase productivity, then I’m all for them.

There are two parts to learning craftsmanship: knowledge and work. You must gain the knowledge of principles, patterns, practices, and heuristics that a craftsman knows, and you must also grind that knowledge into your fingers, eyes, and gut by working hard and practicing.

Learning to write clean code is hard work. It requires more than just the knowledge of principles and patterns. You must sweatover it.

You must practice it yourself, and watch yourself fail. You must watch others practice it and fail. You must see them stumble and retrace their steps. You must see them agonize over decisions and see the price they pay for making those decisions the wrong way.

You are reading this book for two reasons. First, you are a programmer. Second, you want to be a better programmer. Good. We need better programmers.

It was the bad code that brought the company down.

Later equals never.

Why does this happen to code? Why does good code rot so quickly into bad code? We have lots of explanations for it.

  • We complain that the requirements changed in ways that thwart the original design.
  • We bemoan يندب يتحسر the schedules that were too tight to do things right.
  • We blather about stupid managers and intolerant customers.

But the fault, dear Dilbert, is not in our stars, but in ourselves.

We are unprofessional.

 

“But wait!” you say. “If I dont do what my manager says, Ill be fired.” Probably not.

Most managers want the truth, even when they don’t act like it. Most managers want good code, even when they are obsessing about the schedule.

They may defend the schedule and requirements with passion; but thats their job. Its your job to defend the code with equal passion.

 

The onlyway to make the deadline—the only way to go fast—is to keep the code as clean as possible at all times.

 

The bad news is that writing clean code is a lot like painting a picture. Most of us know when a picture is painted well or badly. But being able to recognize good art from bad does not mean that we know how to paint. So too being able to recognize clean code from dirty code does not mean that we know how to write clean code!

 

We are Authors, The next time you write a line of code, remember you are an author, writing for readers who will judge your effort.

 

The ratio of time spent reading vs. writing is well over 10:1.

We are constantly reading old code as part of the effort to write new code.

 

Making it easy to read actually makes it easier to write.

 

Leave the campground cleaner than you found it.

 

Thank you and Keep It Simple & Straightforward 🙂

~:H}{H:~

Advertisements

Hands-on labs for Windows 8

ImageImage

Now you can learn to create a Windows Store app using C# and XAML.

The hands-on labs in this package immerse you in Windows 8 app development—specifically, development of a Windows Store app using C# and XAML.

What’s in the package

  • Assets
  • Lab 1 – Creating a Windows Store app
  • Lab 2 – Orientation, snapping, and Semantic Zoom
  • Lab 3 – Searching and sharing
  • Lab 4 – App bars and media capture
  • Lab 5 – Process Lifetime Management
  • Lab 6 – Settings and preferences
  • Lab 7 – Tiles and notifications
  • Lab 8 – The Windows Store APIs

You can download the package from here.

Thank you and Keep It Simple & Straightforward!

~:H}{H:~

How to Install Windows 8 on VHD

I will start with the main steps:

  • Create the VHD and Attach it.
  • Create a Windows 8  bootable USB device.
  • Install windows 8 using the bootable USB on the VHD.

Let’s do it. 🙂

Create the VHD and Attach it.

1. Open Disk Management and Create VHD.

2. Specify the virtual hard disk location on the machine and size.

3. Initialize Disk

4. Create New Simple Volume…

Create a Windows 8  bootable USB device

1. Choose ISO file

2. Choose media type

3. Insert USB device

4. Begin copying…

Install windows 8 using the bootable USB on the VHD.

1. Restart your PC and begin installing windows normally.

2. At the step that you choose which hard desk drive to install on it, we need to attach our VHD and select it. Press Shift+F10 command line will appear, then you need to type the following…

diskpart
select vdisk file="E:\windows8VHD.vhd"
attach vdisk
list volume
exit

3. Finally, the VHD will be listed and you can choose it to continue installing windows.
——————————————–

Thank you,

Hossam Hassan

Keep It Simple & Straightforward!

~:H}{H:~

Windows 8 Developer Boot Camp

You’ve been invited to join Microsoft in their lead up to the Windows 8 launch for our very first Windows 8 Boot Camp for developers covering app development on the Windows 8 platform, Windows Phone and Windows Azure and Visual Studio 2012. Come spend two days and immerse yourself in code!

When you register you need to print your ticket and bring it with you to the event. 🙂

You can register from here

Thank you and see you there 🙂

Keep It Simple Straightforward!

~:H}{H:~

AutoComplete Textbox

Here you are the steps to follow if you need to make a Auto-Complete Textbook. We are used to display the Employees in a Drop Down List, it takes some time from the user to find and select the desired Employee. Now it is Very Easy & Our Customer is Very Happy 🙂

The solution in brief:

  • Web service to search for the desired employee and return the result.
  • Drop Down List for departments used to filter our data by department.
  • Text box for the Employee Name.
  • jquery-ui-1.8.24.custom.min.js script file used to implement the auto complete manner.

Let’s do it 🙂

1. Add New WebService to you Application with name “EmployeeWebService.asmx”

[System.Web.Script.Services.ScriptService]
public class EmployeeWebService : System.Web.Services.WebService
{

[WebMethod(EnableSession = true)]
public List GetEmployees(string criteria)
{
var result = new List();
var lstDepartmentEmployees = (List)HttpContext.Current.Session["LstEmployees"];

if (lstDepartmentEmployees != null)
{
var lstEmployees = lstDepartmentEmployees.Where(e => e.Name.Contains(criteria)).ToList();
result = lstEmployees.Select(e => new KeyValuePair { Key = e.Id.ToString(), Value = e.Name }).ToList();
}

return result;
}
}

As shown above it has only one method called GetEmployees which takes one parameter called criteria (employee name to search for).

This method will search the Employee List stored in the Session and return the result as KeyValuePair list.(Key–> Id, Value–> Employee Name)

public class KeyValuePair
{
public string Key { get; set; }
public string Value { get; set; }
}

2. Add New Page with a Drop Down List , Textbox, Hidden Field and Button.

The drop down list for departments to implement employee filtration.

The text box to enter the employee name used in search process.

The hidden field used to save the selected Employee Id, we will use it in saving or display process.

The button used for just read from the hidden field to be sure it works fine.

3. Add your JQuery script code which is responsible for auto complete manner.


<script type="text/javascript">
$(document).ready(function () {
$("#TxtEmployeeName").autocomplete({
source: function (request, response) {
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "/WebService/EmployeeWebService.asmx/GetEmployees",
data: "{'criteria':'" + request.term + "'}",
dataType: "json",
success: function (data) {
response($.map(data.d, function (item) {
return {
label: item.Value,
value: item.Value,
id: item.Key
};
}));
},
change: function (event, ui) {
$('#HFSelectedEmployeeId').val(ui.item.id);
alert($('#HFSelectedEmployeeId').val);
return false;
},
error: function (result) {
alert("Unable to load data");
}
});
},
minLength: 1,
select: function (event, ui) {
$('#HFSelectedEmployeeId').val(ui.item.id);
//alert($('#HFSelectedEmployeeId').val());
return false;
}
});
});
</script>

We will make an Ajax request to our web service method, pass to it the text to search, map the result and save the employee id in case of selection completed.

4. Don’t forget to add reference to Jquery UI script file and Css file.

<script src=”Scripts/jquery-1.8.2.min.js” type=”text/javascript”></script>
<script src=”Scripts/jquery-ui-1.8.24.custom.min.js” type=”text/javascript”></script>

<link href=”Styles/jquery-ui-1.8.24.custom.css” rel=”stylesheet” type=”text/css” />

5. Finally, Do what is needed so that you are ready to run your application.

The final result should look like the following…

Thank you, and Keep it Simple & Straightforward!

~:H}{H:~