Style question
-
(I know C++) Always limit the number of parameters, especially returned parameters (references in C++); Use a struct to hold the settings. It will also be easier to maintain if you decide to add or remove data to the parameters and/or need to do some processing on the data in the struct (in C++ one would make it a class (*)) If necessary, return a bool if the function can fail and you need to know about it. (*) even if there are no significant difference between a class and a struct
I'd rather be phishing!
Thank you... that was my eventual thought, but it took me a while to get there.
-
Holy crap on a cracker... ask a simple question... I know what a function is and what a procedure is and how they are used. I started with a procedure: GetSettings and passed in a number of local variables. But, then I thought, a procedure shouldn't be returning values, that is what a function does. However, there is more than one value to return (currently 6), so I decided to use a stucture and have the function return a single structure with values in each element. The series of data is: source directory for file to be processed, from e-mail address, to e-mail address, SMTP server, report type (row or column based), single e-mail or an e-mail per file processed. Now, having been on here for some time, I have seen flame wars on style: what should a procedure to, what should a function do, blah, blah, blah.... So, simple question of style and maintainability...
Using a struct seems a good way to go. Another option is to use an XML string, which is a bit more overhead but could be handy if you need to write to and retrieve from disk/database. But otherwise the struct is probably better.
-
Holy crap on a cracker... ask a simple question... I know what a function is and what a procedure is and how they are used. I started with a procedure: GetSettings and passed in a number of local variables. But, then I thought, a procedure shouldn't be returning values, that is what a function does. However, there is more than one value to return (currently 6), so I decided to use a stucture and have the function return a single structure with values in each element. The series of data is: source directory for file to be processed, from e-mail address, to e-mail address, SMTP server, report type (row or column based), single e-mail or an e-mail per file processed. Now, having been on here for some time, I have seen flame wars on style: what should a procedure to, what should a function do, blah, blah, blah.... So, simple question of style and maintainability...
Tim Carmichael wrote:
Holy crap on a cracker... ask a simple question...
Your question wasn't all that thought out though. It was basically asking something like "what does green look like?" So, holy crap on a cracker another post with some vague nonsense!! At least this post was better.
Jeremy Falcon
-
Before you get your flamethrowers out... this is a question about coding style and preference, not asking a coding question per se... While I do code, it is not as often as it used to be, and I have to rethink how some things are/should be done. In a .NET application, what process should be used to obtain a series of Setting values? A procedure? A function? Local variables? Global variables? Pass a structure? Just looking for advice... Tim
You know this is a programming question, right? and it is not a matter of style but rather doing things the correct way or the wrong way, IMHO. Settings could be put in a app.config or web.config file and recalled in your application using the .net library/class ConfigurationManager, I believe.
-
Holy crap on a cracker... ask a simple question... I know what a function is and what a procedure is and how they are used. I started with a procedure: GetSettings and passed in a number of local variables. But, then I thought, a procedure shouldn't be returning values, that is what a function does. However, there is more than one value to return (currently 6), so I decided to use a stucture and have the function return a single structure with values in each element. The series of data is: source directory for file to be processed, from e-mail address, to e-mail address, SMTP server, report type (row or column based), single e-mail or an e-mail per file processed. Now, having been on here for some time, I have seen flame wars on style: what should a procedure to, what should a function do, blah, blah, blah.... So, simple question of style and maintainability...
Tim Carmichael wrote:
ask a simple question...
that wasn't obvious from your wording as you can see by the responses! I'd definitely say that using a struct (or a class) is the way to go, assuming this us used something along the lines of
{
var myNewStruct = getSettings(someIdentifyingParameters);
SendEmail(myNewStruct)
}But if the contents of the struct are relevant to the context of the class, then I'd have them defined as a private field
PooperPig - Coming Soon
-
Before you get your flamethrowers out... this is a question about coding style and preference, not asking a coding question per se... While I do code, it is not as often as it used to be, and I have to rethink how some things are/should be done. In a .NET application, what process should be used to obtain a series of Setting values? A procedure? A function? Local variables? Global variables? Pass a structure? Just looking for advice... Tim
Take that hat off for a start, Dahling. It doesn't fit you at all.
I wanna be a eunuchs developer! Pass me a bread knife!
-
You know this is a programming question, right? and it is not a matter of style but rather doing things the correct way or the wrong way, IMHO. Settings could be put in a app.config or web.config file and recalled in your application using the .net library/class ConfigurationManager, I believe.
I agree with this, this is the way I would go. You can create settings sections as well and put them in unique .config files. By doing it this way, all the heavy lifting is done for you by the ConfigurationManager class. This article makes a fair stab at describing how to use it (it's a lot simpler in practice once you get your head around it).. Custom Configuration Sections for Lazy Coders[^]
How do you know so much about swallows? Well, you have to know these things when you're a king, you know.
-
Take that hat off for a start, Dahling. It doesn't fit you at all.
I wanna be a eunuchs developer! Pass me a bread knife!
On Thursdays I dress smartly to increase the SNR with Dress Down Friday. Today I wore a new shirt made for me in New York(excellent value!), my grey worsted suit and a Bowler; also I carried my city umbrella(it might rain) and wore a fine tie by Hawes & Curtis in Gloucester. And now if you don't mind, I have an appointment for lunch. :(
-
Holy crap on a cracker... ask a simple question... I know what a function is and what a procedure is and how they are used. I started with a procedure: GetSettings and passed in a number of local variables. But, then I thought, a procedure shouldn't be returning values, that is what a function does. However, there is more than one value to return (currently 6), so I decided to use a stucture and have the function return a single structure with values in each element. The series of data is: source directory for file to be processed, from e-mail address, to e-mail address, SMTP server, report type (row or column based), single e-mail or an e-mail per file processed. Now, having been on here for some time, I have seen flame wars on style: what should a procedure to, what should a function do, blah, blah, blah.... So, simple question of style and maintainability...
Tim Carmichael wrote:
So, simple question of style and maintainability...
Yes, but maintained by who? If you're working in a code base maintained by others, follow the pattern that they set and do what they do. Not because it's stylistically right, but more because they'll understand what you've done quicker with less chance of understanding it wrong. If you're writing something that only you will maintain, or is throwaway, then do what seems right, or whichever way you want to practice.
We can program with only 1's, but if all you've got are zeros, you've got nothing.
-
Before you get your flamethrowers out... this is a question about coding style and preference, not asking a coding question per se... While I do code, it is not as often as it used to be, and I have to rethink how some things are/should be done. In a .NET application, what process should be used to obtain a series of Setting values? A procedure? A function? Local variables? Global variables? Pass a structure? Just looking for advice... Tim
Just do what a tool such as Resharper or CodeRush suggests Then you can spend your time thinking about more important things
-
Before you get your flamethrowers out... this is a question about coding style and preference, not asking a coding question per se... While I do code, it is not as often as it used to be, and I have to rethink how some things are/should be done. In a .NET application, what process should be used to obtain a series of Setting values? A procedure? A function? Local variables? Global variables? Pass a structure? Just looking for advice... Tim
I manage my own settings (i.e. "config file") using environment variables to determine where to store them (e.g. "Program Data"; "User Data"; "Documents and Settings"; whatever ... depends on the OS). You can use the .NET "built-in" functions for managing "user.config", but .NET tends to create multiple folders, and copies of your config.file, when you start "versioning" your program (can get really confusing / messy ... IMO). As for "consumers" of your settings ... use "dependency injection". (In some cases, settings could be stored on a web server and accessed via a web service by the clients when you're dealing with an app that is "distributed"; e.g. kiosks). Since we're talking .NET ... manage you settings with a class; serialize and deserialize them using XML; and retrieve them initially at app start-up. (A "procedure" is just a "function" that "returns" void ... IMO).