Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. Style question

Style question

Scheduled Pinned Locked Moved The Lounge
questioncsharp
22 Posts 16 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Tim Carmichael
    wrote on last edited by
    #1

    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

    J A R M P 12 Replies Last reply
    0
    • T Tim Carmichael

      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

      J Offline
      J Offline
      Jeremy Falcon
      wrote on last edited by
      #2

      Tim Carmichael wrote:

      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?

      That's an open ended question. Sounds like marketing trying to describe tech, or a way to dance around asking a real programming question. Ether way, what you're talking about is application architecture and design. Crack open a book man, that's what we did.

      Jeremy Falcon

      1 Reply Last reply
      0
      • T Tim Carmichael

        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

        A Offline
        A Offline
        Afzaal Ahmad Zeeshan
        wrote on last edited by
        #3

        Actually I don't understand your question, but I will explain the usage of these, procedure, I have used them in SQL but never in .NET so no wrong information, A function is something that you write to recall the very same set of code block. For example, you write a code that gets repeated at many locations in your software, so you create a function, and place that code block in it and recall it each time you want to use it. Like this

        private void SomeFunction () {
        // code block here..
        }

        Local variables are the variables present or defined inside any function block, like main function or any custom function whereare Global functions are present anywhere inside the class, that are accessible in every code block on that class file. A Structure is opposite of Class, similar is behaviour, in struct, you send the object itself inside the function, whereas in the class, you just send the copy of it. In struct you actually pass the reference of the object. You can use them in your coding to make your software efficient. Sorry for not-answering your question because I don't understand it.

        Favourite line: Throw me to them wolves and close the gate up. I am afraid of what will happen to them wolves - Eminem ~! Firewall !~

        1 Reply Last reply
        0
        • T Tim Carmichael

          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

          M Offline
          M Offline
          Manfred Rudolf Bihy
          wrote on last edited by
          #4

          Tim Carmichael wrote:

          Just looking for advice...

          Try this here CP forum: http://www.codeproject.com/Forums/369270/Design-and-Architecture.aspx[^]. ;) Cheers!

          "I had the right to remain silent, but I didn't have the ability!"

          Ron White, Comedian

          1 Reply Last reply
          0
          • T Tim Carmichael

            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

            R Offline
            R Offline
            Ravi Bhavnani
            wrote on last edited by
            #5

            By "series", do you mean a time series (i.e. values that can change over time) or a group (i.e. a batch) of setting values? /ravi

            My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

            1 Reply Last reply
            0
            • T Tim Carmichael

              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

              P Offline
              P Offline
              PIEBALDconsult
              wrote on last edited by
              #6

              Tim Carmichael wrote:

              should be used

              Whatever you are most comfortable with. Don't just follow the pack. Actually, it's not a very clear question. Where do the "Settings" come from?

              1 Reply Last reply
              0
              • T Tim Carmichael

                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

                Mike HankeyM Offline
                Mike HankeyM Offline
                Mike Hankey
                wrote on last edited by
                #7

                For me a pair of Levi's and a T-shirt? :)

                Have you ever just looked at someone and knew the wheel was turning but the hamster was dead? Trying to understand the behavior of some people is like trying to smell the color 9.

                1 Reply Last reply
                0
                • T Tim Carmichael

                  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

                  J Offline
                  J Offline
                  JMK NI
                  wrote on last edited by
                  #8

                  I tend to follow these guidelines - https://www.thc.org/root/phun/unmaintain.html[^] Good luck!

                  1 Reply Last reply
                  0
                  • T Tim Carmichael

                    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

                    T Offline
                    T Offline
                    Tim Carmichael
                    wrote on last edited by
                    #9

                    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...

                    R M S J L 6 Replies Last reply
                    0
                    • T Tim Carmichael

                      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...

                      R Offline
                      R Offline
                      Ravi Bhavnani
                      wrote on last edited by
                      #10

                      OK, seems pretty straightforward then.

                      SettingsSpec settingsSpec = new SettingsSpec { Var1=..., Var2=..., etc };
                      Settings s = SettingsManager.Instance.GetSettings(settingsSpec);

                      If you prefer to go the dependency injection way, do:

                      SettingsSpec settingsSpec = new SettingsSpec { Var1=..., Var2=..., etc };
                      SettingsManager settingsMgr = new SettingsManager(settingsSpec);
                      Settings s = settingsManager.GetSettings();

                      /ravi

                      My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

                      1 Reply Last reply
                      0
                      • T Tim Carmichael

                        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...

                        M Offline
                        M Offline
                        Maximilien
                        wrote on last edited by
                        #11

                        (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!

                        T 1 Reply Last reply
                        0
                        • M Maximilien

                          (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!

                          T Offline
                          T Offline
                          Tim Carmichael
                          wrote on last edited by
                          #12

                          Thank you... that was my eventual thought, but it took me a while to get there.

                          1 Reply Last reply
                          0
                          • T Tim Carmichael

                            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...

                            S Offline
                            S Offline
                            StatementTerminator
                            wrote on last edited by
                            #13

                            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.

                            1 Reply Last reply
                            0
                            • T Tim Carmichael

                              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...

                              J Offline
                              J Offline
                              Jeremy Falcon
                              wrote on last edited by
                              #14

                              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

                              1 Reply Last reply
                              0
                              • T Tim Carmichael

                                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

                                S Offline
                                S Offline
                                Slacker007
                                wrote on last edited by
                                #15

                                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.

                                L 1 Reply Last reply
                                0
                                • T Tim Carmichael

                                  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...

                                  L Offline
                                  L Offline
                                  Lost User
                                  wrote on last edited by
                                  #16

                                  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

                                  1 Reply Last reply
                                  0
                                  • T Tim Carmichael

                                    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

                                    M Offline
                                    M Offline
                                    Mark_Wallace
                                    wrote on last edited by
                                    #17

                                    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!

                                    S 1 Reply Last reply
                                    0
                                    • S Slacker007

                                      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.

                                      L Offline
                                      L Offline
                                      Lost User
                                      wrote on last edited by
                                      #18

                                      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.

                                      1 Reply Last reply
                                      0
                                      • M Mark_Wallace

                                        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!

                                        S Offline
                                        S Offline
                                        Simon ORiordan from UK
                                        wrote on last edited by
                                        #19

                                        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. :(

                                        1 Reply Last reply
                                        0
                                        • T Tim Carmichael

                                          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...

                                          P Offline
                                          P Offline
                                          patbob
                                          wrote on last edited by
                                          #20

                                          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.

                                          1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups