Hi,
So there's the "Do One Thing" rule in the book "Clean Code".
But how far do we really have to take this.
For example the following statements:
Settings.Default.BaudRate = baudRate;
Settings.Default.COMPort = port;
Settings.Default.DataBits = dataBits;
Settings.Default.Handshake = handshake;
Settings.Default.Parity = parity;
Settin...
PHP/MySQLisolating database access in class - how to handle multiple row Selects
Here’s a coding question.
I isolated all DB access functions in a class
<?php
class DB {
var $conn;
function DBClass () {
@$this-> conn = mysqli_connect (DB_SERVER, DB_USER, DB_PASS, DB_NAME);
}
function validateUse...
In a recent VB.NET project I adopted the naming conventions I'm used to using in C#. Namely, often calling a variable the same name as the class it references, only with a different case, e.g.
Foo foo = new Foo(); // C#
Dim foo As New Foo() ' VB.NET
I find this is often the clearest way to write code, especially for small methods. Th...
This is a question of style. On date night with my wife she says that I have none and should seek advice.
In my ASP.NET MVC View I pick a sprite based on a boolean value set in the model like this:
<div class="sprite-icon_dog<% =(Model.HasNewDog ? "_new" : "") %>"></div>
This is ugly and I don't like it.
My objective is to use the s...
It is quite possible that I may not have got the point, but I really can't figure out how ASP.Net MVC's HTML Helpers can help me. Here's a sample: -
HTML:
<a href="ActionName" target="_blank">Click Me</a>
HTML Helper:
<%= Html.ActionLink("Click me", "ActionName", null, new {target="blank"}) %>
My eyes are reading HTML more easily,...
When a function returns a boolean you can easily
if (task()){
// it worked!
}else{
// it failed.
}
But when it returns multiple different values it gets messier
var status = task();
if (status == 1){
// hmm
}else if (status == 2){
// hmmmmm
}else if (status == 3){
// hmmmmmmmm!
}
..is there a neater way of handling ...
Possible Duplicate:
What did you do to develop good code designing practices
There are two different situations.
you read someone's code, and you know what they are doing intuitively.
you read someone's code, even there are many comments, but you really don't know what he wants to do.
I wonder whether or not there are best ...
Sun's "Code Conventions for the Java Programming Language" was last updated April 1999. Ten years later a lot has changed in the language, as well as general usage patterns. Are there more up to date, widely adopted standards?
Most guidelines omit specifying file encoding and line endings. Sun recommends mixed tabs and spaces. The E...
Is there any need for code with author's name added in every function or even the files?
Yes code will be in source control and many programmers involved
...
I code in Python a lot, and I frequently create classes. Now, I'm not sure if this is good Python form, but I just declare a class in the same file as my main().
class foo {
...
}
I'm wondering if it's good form in Java to do the same?
For example,
class foo {
public static int name;
public static int numPoints;
public s...
I'm working with websites written in PHP, along with many other programmers, and sometimes I have to deal with really awful code.
Indentation totally messed up, curly braces in the wrong places, terrible whitespace use, it really hurts my eyes and actually makes my work harder and take longer.
Is there a tool where you can specify your...
I have an interface in c# that helps retrieving of data from a custom archive on server. The interface looks like this:
public interface IRetrieveData
{
bool OkToRetrieve(SomeData data); // Method in question...
bool RetrieveToLocal(SomeData data);
}
This interface is implemented by the clients that retrieve the data to the lo...
I've been having a discussion with my coworkers as to whether to prefix overridden methods with the virtual keyword, or only at the originating base class.
I tend to prefix all virtual methods (that is, methods involving a vtable lookup) with the virtual keyword. My rationale is threefold:
Given that C++ lacks an override
keyword, the...
I'm using StyleCop and FxCop tools to improve my code but I came to a place where there are two rules, one in StyleCop and one in FxCop that exclude each other. If I fix my code to match the rule from StyleCop then FxCop validation fails and vice versa.
First rule is SA1200 from StyleCop which says that all using directives must be plac...
To read contents of a file:
data = open(filename, "r").read()
The open file immediately stops being referenced anywhere, so the file object will eventually close... and it shouldn't affect other programs using it, since the file is only open for reading, not writing.
EDIT: This has actually bitten me in a project I wrote - it prompte...
I have used the "using" statement in both C# and VB. I agree with all the critics regarding nesting using statements (C# seems well done, VB not so much)
So with that in mind I was interested in improving my VB using statements by "using" more than one system resource within the same block:
Example:
Using objBitmap as New Bitmap(100,...
This is probably a matter of personal preference, but when do you use properties instead of functions in your code
For instance to get an error log I could say
string GetErrorLog()
{
return m_ErrorLog;
}
or I could
string ErrorLog
{
get { return m_ErrorLog; }
}
How do you decide which one to use? I seem to be inconsist...
Is there a best practice for making private methods in classes static? I have a class with a few methods. Some of these can easily be made static, since they simply process data.
Should I make them static or just leave them as is? Is this more of a style issue? Are there performance considerations?
Edit:
http://stackoverflow.com/qu...
I have a custom Menu class written in C++. To seperate the code into easy-to-read functions I am using Callbacks.
Since I don't want to use Singletons for the Host of the Menu I provide another parameter (target) which will be given to the callback as the first parameter (some kind of workaround for the missing "this" reference).
Regis...
I have a generic question about scope and encapsulation. Take two scenarios:
Scenario 1:
// a global application level constant
public static const IS_DEMO_MODE:Boolean = false;
... // somewhere deep in the codebase
private function _myFunction():void
{
if (IS_DEMO_MODE == true) {
// If Demo Mode do not allow this functi...