.net parameters



  • @tdb said:

    @heterodox said:

    @C-Octothorpe said:

    Oh good god, tell me you're joking... Who the fuck is steering the VB.net language design team at MS?

    Wait, what's the problem? To me that's like int main(int argc, char** argv); vs. int main(void); - if you don't plan on using the parameters you can omit them.

    I think C-Octothorpe, like me, saw an implication that you could access those parameters even though they are not declared. I don't know if this is the case and don't care enough to find out, so perhaps one of the VB coders here will tell us.

     

    It works just like heterdox suggests.  If you aren't using the parameters you can ommit them, otherwise you need them.  Its a new thing in .net 4.0 and I lurvz it.  Saves me typing and you can immediately see if those parameters are used in the handler or not.



  • @heterodox said:

    @C-Octothorpe said:

    Oh good god, tell me you're joking...  Who the fuck is steering the VB.net language design team at MS?

    Wait, what's the problem? To me that's like int main(int argc, char** argv); vs. int main(void); - if you don't plan on using the parameters you can omit them.

    But why omit them?  I mean, there is the concept of optional/default parameters in C#, but IMO it kills readability.  If you're not going to use the parameters, then create a parameterless overload.  It's more verbose, but you can more easily see which method overload you're calling and what's going on.



  • @C-Octothorpe said:

    @heterodox said:

    @C-Octothorpe said:

    Oh good god, tell me you're joking...  Who the fuck is steering the VB.net language design team at MS?

    Wait, what's the problem? To me that's like int main(int argc, char** argv); vs. int main(void); - if you don't plan on using the parameters you can omit them.

    But why omit them?  I mean, there is the concept of optional/default parameters in C#, but IMO it kills readability.  If you're not going to use the parameters, then create a parameterless overload.  It's more verbose, but you can more easily see which method overload you're calling and what's going on.

    Why would you create a parameterless overload of a method that doesn't use its parameters?  Also, it seems that since you have declare that it handles a certain button, one of the functions wouldn't be able to have that code and simply wouldn't be used.


  • @tdb said:

    I'd love to see you write an implementation of the CLR without using pointers. Or any self-bootstrapping language. Or an OS.

    It seems you are intentionally misinterpreting what he said when it was quite clear. Pointers are necessary for some low-level stuff, but most applications DO NOT need them.

    @tdb said:

    Perhaps I'm just getting old, but I see all kinds of automatic memory management as part of the "everyone can program" fad that's been going on for a decade or so (there were some attempts even earlier but they never caught much wind). The danger here is that as programming is dumbed down, dumber people are going to pick it up, and managers are too dumb to see the difference so the dumb people get hired and write dumb code. If programming had remained hard, we might have less different applications, but the existing ones would be of higher quality.

    I am dumbstruck. 1) Automatic memory management is definitely more than a decade old. 2) Manual memory management does not improve application quality. It's like you've never used a mid-80s DOS program, or a mid-90s Windows program or a mid-anytime Linux program. 3) Making things intentionally hard does not improve quality. Why would you think this?

    Actually, fuck it, there's just too much dumb in your comment to bother.

    @tdb said:

    Well explained != intuitive

    I love that in one paragraph you bemoan unqualified, "dumb" programmers and in the next you complain that reading documentation is hard.



  • @Sutherlands said:

    Why would you create a parameterless overload of a method that doesn't use its parameters
    Good point, but that's one level higher than I was trying to address.  I agree, why even have a parameterless overload if overload with the parameters doesn't do anything with them anyway.  But that's another storey for another day...

    @Sutherlands said:

    Also, it seems that since you have declare that it handles a certain button, one of the functions wouldn't be able to have that code and simply wouldn't be used.
    Sorry, I'm not sure what you're trying to say here...



  • @C-Octothorpe said:

    @Sutherlands said:

    Also, it seems that since you have declare that it handles a certain button, one of the functions wouldn't be able to have that code and simply wouldn't be used.
    Sorry, I'm not sure what you're trying to say here...

    In the original post that caused this issue:

    "Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click"

    vs

    "Private Sub Button1_Click() Handles Button1.Click"

    Only one method can handle a particular button (I assume) - why would you choose the first signature instead of the second if you don't need the params?



  • @Peraninth said:

    @tdb said:

    @heterodox said:

    @C-Octothorpe said:

    Oh good god, tell me you're joking... Who the fuck is steering the VB.net language design team at MS?

    Wait, what's the problem? To me that's like int main(int argc, char** argv); vs. int main(void); - if you don't plan on using the parameters you can omit them.

    I think C-Octothorpe, like me, saw an implication that you could access those parameters even though they are not declared. I don't know if this is the case and don't care enough to find out, so perhaps one of the VB coders here will tell us.

     

    It works just like heterdox suggests.  If you aren't using the parameters you can ommit them, otherwise you need them.  Its a new thing in .net 4.0 and I lurvz it.  Saves me typing and you can immediately see if those parameters are used in the handler or not.

    Who types event procedure declarations?  Do you code in notepad?


  • @Jaime said:

    Who types event procedure declarations?  Do you code in notepad?
    To be fair he just learned about class pass-by-value semantics.



  • @tdb said:

    @heterodox said:

    @C-Octothorpe said:

    Oh good god, tell me you're joking...  Who the fuck is steering the VB.net language design team at MS?

    Wait, what's the problem? To me that's like int main(int argc, char** argv); vs. int main(void); - if you don't plan on using the parameters you can omit them.

    I think C-Octothorpe, like me, saw an implication that you could access those parameters even though they are not declared. I don't know if this is the case and don't care enough to find out, so perhaps one of the VB coders here will tell us.

    I just tried it; neither sender nor e can be accessed.

    BTW, C# has a "magic variable" scenario that has always bothered me:

            private int x;
            public int X
            {
                get
                {
                    return x;
                }
                set
                {
                    x = value;
                }
            }



  • @Sutherlands said:

    @tdb said:

    Have you ever used valgrind?
    Did I say it was impossible to track down memory leaks?  No.  It's not easy.  And it's certainly not as easy as not having any in the first place.

    It's not hard either, given proper tools. valgrind will point you to the exact line of code where the leaked allocation occurred, and then you can add the the matching free. I'm not going to generalize here since there are as many styles as there are programmers, but in my code the allocation is almost always in a class constructor, which means the free should go to the destructor. Temporaries are stack variables and get destroyed automatically when they go out of scope (that's one of the reasons I love C++, incidentally; you know exactly when something is going to get destroyed, which enabled all kinds of nice things like RAII).

    @Sutherlands said:
    @tdb said:

    I'd love to see you write an implementation of the CLR without using pointers. Or any self-bootstrapping language. Or an OS.

    You want me to write an OS in .Net?  I'm sure you had a point here, but I'm not sure what it was...

    One thing I use to rate programming languages is whether or not it's self-contained, i.e. can the language be used to write an implementation of itself. Roughly speaking, this requires two things: access to OS system calls (for interacting with the system) and low-level memory management (for implementing higher-level memory management, if nothing else). So far C and C++ are the only languages I know to certainly meet these requirements (although they require the use of an asm block to access the syscall interrupt, but at least the language spec provides that, even if the exact semantics of the asm code itself are left to the implementation). C# with unsafe code probably meets the memory management requirement at least. D might meet both, but I haven't studied it enough to know.

    Writing an OS is taking this to the extreme; if you can write an OS in a language, you can do anything with it. Thus the languages capable of that sit on the highest tier of my scale.



  • @Sutherlands said:

    @C-Octothorpe said:

    @Sutherlands said:

    Also, it seems that since you have declare that it handles a certain button, one of the functions wouldn't be able to have that code and simply wouldn't be used.
    Sorry, I'm not sure what you're trying to say here...

    In the original post that caused this issue:

    "Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click"

    vs

    "Private Sub Button1_Click() Handles Button1.Click"

    Only one method can handle a particular button (I assume) - why would you choose the first signature instead of the second if you don't need the params?

    At the end of the day, it's just syntactic sugar, like auto properties (and properties themselves, too), object initializers, etc.  It introduces ambiguity, not for the compiler, but for the developer, which is far worse. 

    So you have managed to save typing 4-8 lines of code, but at a cost to readability, which has a real cost: developer time.  You can use method signatures to your advantage, but this IMO just shits on that and I avoid it like the plague.



  • @Jaime said:

    @tdb said:

    @heterodox said:

    @C-Octothorpe said:

    Oh good god, tell me you're joking...  Who the fuck is steering the VB.net language design team at MS?

    Wait, what's the problem? To me that's like int main(int argc, char** argv); vs. int main(void); - if you don't plan on using the parameters you can omit them.

    I think C-Octothorpe, like me, saw an implication that you could access those parameters even though they are not declared. I don't know if this is the case and don't care enough to find out, so perhaps one of the VB coders here will tell us.

    I just tried it; neither sender nor e can be accessed.

    BTW, C# has a "magic variable" scenario that has always bothered me:

            private int x;
            public int X
            {
                get
                {
                    return x;
                }
                set
                {
                    x = value;
                }
            }

    Wha?  Magic variable?  Are you talking about case-sensitivity or the "value" keyword in the setter?


  • @Sutherlands said:

    Only one method can handle a particular button (I assume) - why would you choose the first signature instead of the second if you don't need the params?

    Actually you can add as many as you want but the order of execution is not guaranteed



  • @tdb said:

    Writing an OS is taking this to the extreme; if you can write an OS in a language, you can do anything with it. Thus the languages capable of that sit on the highest tier of my scale.

    "Cement is used to make the automobile factory, therefore the automobile should be made of cement."



  • @C-Octothorpe said:

    Are you talking about case-sensitivity or the "value" keyword in the setter?
    value



  • @morbiuswilters said:

    I love that in one paragraph you bemoan unqualified, "dumb" programmers and in the next you complain that reading documentation is hard.

    I wish I could explain this in a way that made sense.  I swear I'm not a retarded monkey that just can't read.  Let me try again.

    Steps to learning C#:

    1. load existing C# project that company will have me working on
    2. start looking through files/classes/functions
    3. start working on adding very small unimportant features
    4. lookup how to pass parameters in C# to make sure i'm doing it right
    5. find http://msdn.microsoft.com/en-us/library/0f66670z.aspx and read the paragraph.  look at the example code.
    6. ok, it looks like passing parameters is exactly the same in C# as it is in C, move on to other things
    7. get curious a few weeks later if I should be passing classes by reference purely to help with performance
    8. do some googling and holy shit there are value type objects and reference type objects!  where did those come from?!?
    9. get slightly paranoid that i've used reference type objects wrong in past code that is already live

    You can probably argue (and be 100% right) that I am trwtf for following this learning path, but if that page had loaded the .net 2003 version first I could have skipped steps, 6, 7, 8, 9.  At that point in my C# / .net knowledge I did not know anything about value type objects and reference type objects.  The MSDN .net documentation is some of the best language documentation out there imo, I just did not know there was more reading I needed to do.  Shirley I am not the only person alive out there that followed this learning path and missed the important information.



  • @tdb said:

    One thing I use to rate programming languages is whether or not it's self-contained

    Huh, the thing I use is how quickly and accurately you can accomplish a given task.


  • @Peraninth said:

    Shirley I am not the only person alive out there that followed this learning path and missed the important information.

    You're probably not, but it certainly is what the problem is.  Learning by reading code (possibly very bad code).  You should probably read an introduction to C# book, or at least skim it, to get the basic stuff down.


  • @Jaime said:


    Who types event procedure declarations?  Do you code in notepad?

    Wow, you really think its faster to scroll through the list of objects and then scroll through the list of events than it is to just type the event with auto-complete tabbing?  For an added bonus my hands never have to leave the keyboard.  For an added added bonus I get function names which describe what the function does, not just the even it handles (which in vb.net is listed right out to the side with that convenient handles declaration).



  • @morbiuswilters said:

    @tdb said:
    Well explained != intuitive

    I love that in one paragraph you bemoan unqualified, "dumb" programmers and in the next you complain that reading documentation is hard.

    I may love powerful languages, but that doesn't mean I also like ones that are inconsistent. The syntax should be a clue to what the code does, and in this case it's ambiguous.



  • @tdb said:

    @morbiuswilters said:
    @tdb said:
    Well explained != intuitive
    I love that in one paragraph you bemoan unqualified, "dumb" programmers and in the next you complain that reading documentation is hard.

    I may love powerful languages, but that doesn't mean I also like ones that are inconsistent. The syntax should be a clue to what the code does, and in this case it's ambiguous.

    Do you also use hungarian notation?


  • @Peraninth said:

    @Jaime said:

    Who types event procedure declarations?  Do you code in notepad?

    Wow, you really think its faster to scroll through the list of objects and then scroll through the list of events than it is to just type the event with auto-complete tabbing?
    Yes.

    For "Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click", intellisense can cut the 108 keystrokes down to 54, that's still not faster than the GUI.  You also have to know the proper type for the second parameter; since they all inherit from System.EventArgs, if you just guess System.EventArgs, it will compile fine.

    Also, if you are using tab for autocompletion, you are wasting keystrokes.



  • @Jaime said:

    @Peraninth said:

    @Jaime said:

    Who types event procedure declarations?  Do you code in notepad?

    Wow, you really think its faster to scroll through the list of objects and then scroll through the list of events than it is to just type the event with auto-complete tabbing?
    Yes.

    For "Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click", intellisense can cut the 108 keystrokes down to 54, that's still not faster than the GUI.  You also have to know the proper type for the second parameter; since they all inherit from System.EventArgs, if you just guess System.EventArgs, it will compile fine.

    Also, if you are using tab for autocompletion, you are wasting keystrokes.

    Yes, but as I would type it

    "Private Sub SaveIt() Handles button1.Click"

    this only costs me 30 keystrokes and I get all the added benefits I mentioned above. For a direct comparison, I would type it

    "Private Sub SaveIt(sender As Object, e As EventArgs) Handles button1.Click"

    which is still less keystrokes and cleaner imo. Whether or not this is faster would depend on lots of things (typing speed, scroll-fu, number of controls on the page). I can't be the only .net person here that writes out all my events, right?  I also never use the design mode and drag and drop controls onto aspx pages.  I think it produces crap html markup.  Am I alone in that one too?


  • :belt_onion:

    @tdb said:

    @Sutherlands said:
    Pointers are simply unnecessary.  C# has a way to use them, but in all the time I've been writing C#, not once have a said to myself "I really need to use pointers here."

    I'd love to see you write an implementation of the CLR without using pointers. Or any self-bootstrapping language. Or an OS.

    I can think of three such OSes off the top of my head. Cosmos, SharpOS, and Singularity. I'm sure we can (and will) engage in pedantic dickweedery about how tiny portions of all three may be in assembly or C++ or are compiled, but the point is pointers are not as necessary as you seem to think.

     



  • @mountain said:

    Yes, I'm pretty sure this is why Object.clone() exists in Java, and I'm pretty sure there's a .NET equivalent.
     

    actually, we might have TRWTF right here. some time ago i was searching for a way to do just that in .NET, and all i could find was just two solutions:

    1. create constructor override for the class that takes in object of its own type as a parameter, and manually assigns/copies all the properties

    2. make the class serializable (not xml serialization, binary one, or memory, i don't remember how they call it), and then serialize it, create new object of that type, and deserialize the data into it

    (i'm personally talking about .NET 3.5)

     

    i'm pretty sure though, there was no simple .Clone() function that all the objects would implement. i think i even remember the "solution" #2 to be recommended for you to implement as your own extension function to Object class. pretty stupid, imo



  • Is it a deep clone or a shallow clone?  Who knows.  That's why they didn't put it in (in a nutshell).


  • Trolleybus Mechanic

    @Peraninth said:

    I can't be the only .net person here that writes out all my events, right?  I also never use the design mode and drag and drop controls onto aspx pages.  I think it produces crap html markup.  Am I alone in that one too?
     

    I don't usually say "+1", but-- man, +1 to that. I hate the design-time. It's slow as crap, will usually crash VS if you have a custom control. Not to mention that the split view needs to be manually fucking refreshed anytime you make a change.

    I already have a* program that accurately renders the design-view of a webpage. It's called a browser.

    *Okay, I have 4 different programs that all render slightly different versions of the design-view-- and one of those programs renders it 4 different ways.



  • @Sutherlands said:

    Is it a deep clone or a shallow clone?  Who knows.  That's why they didn't put it in (in a nutshell).

    ... or is it even cloneable? Try to clone an instance of System.Windows.Forms.Form; if you manage to do it, I'm positive that bad things will result. Anything that implements IDisposable would likely double free non-managed resources when the second instance is disposed.

    What if you do a deep clone of an object with circular references?



  • The reason C# doesn't normally allow pointers is not only to protect against errors, but also against malice.

    In unmanaged code you can't grant access on code rather than user: Any code you execute is you, and untrusted code can access your confidential data.

    By contrast one of the principles of managed code is "As long as no untrusted code has the right to use pointers, the stack and other code are guaranteed to be untampered." That way, you can decree that a plug-in managed DLL run in a sandbox and be blocked from corrupting the rest of the program.

    That's why only code with full trust can use "unsafe" features.


  • Discourse touched me in a no-no place

    @Sutherlands said:

    Do you also use hungarian notation?
    Which? Systems or Apps?


  • ♿ (Parody)

    @SEMI-HYBRID code said:

    @mountain said:
    Yes, I'm pretty sure this is why Object.clone() exists in Java, and I'm pretty sure there's a .NET equivalent.

    actually, we might have TRWTF right here. some time ago i was searching for a way to do just that in .NET, and all i could find was just two solutions:

    1. create constructor override for the class that takes in object of its own type as a parameter, and manually assigns/copies all the properties

    This is sort of what you have to do to clone an object in java. Except that clone returns an object, so even if you override it and implement the deep clone that you desperately need, you end up having to cast the result.



  • In order to hang a picture on the wall, you have to insert a long hard object in the wall, as expected.

    However, you need to be aware of the object type.
    There are nail type and screw type objects. A nail type object has to be hit hard with a hammer. A screw type object has to be rotated with a screwdriver (which seems quite an inefficient and slow method to me).

    My roommates didn't believe me when I told them (they have been doing room repairs for several years already).

    I'm not sure I understand the reasoning for doing it this way. Is this just to avoid hitting myself on the thumb?



  • Because strained, swiss-cheese prosaic metaphors are the best way of getting a point across.

     

     


  • ♿ (Parody)

    @dhromed said:

    Because strained, swiss-cheese prosaic metaphors are the best way of getting a point across.

    He totally lost me when he didn't use a car analogy.



  • @boomzilla said:

    @dhromed said:
    Because strained, swiss-cheese prosaic metaphors are the best way of getting a point across.

    He totally lost me when he didn't use a car analogy.

     

    You can't really compare screw analogies and car analogies, you know. That's like trying to hang a picture on the wall while in first gear.



  • @SEMI-HYBRID code said:

    i'm pretty sure though, there was no simple .Clone() function that all the objects would implement.

    What, like this one? [url]http://msdn.microsoft.com/en-us/library/system.object.memberwiseclone.aspx[/url]



  • @Spectre said:

    @SEMI-HYBRID code said:
    i'm pretty sure though, there was no simple .Clone() function that all the objects would implement.
    What, like this one? http://msdn.microsoft.com/en-us/library/system.object.memberwiseclone.aspx 
    It's protected, so good luck using it the way that was originally invisioned in this thread.



  • @Spectre said:

    @SEMI-HYBRID code said:
    i'm pretty sure though, there was no simple .Clone() function that would make a deep copy that all the objects would implement.

    What, like this one? http://msdn.microsoft.com/en-us/library/system.object.memberwiseclone.aspx

     

    FTFM

    also, yes, there's a DeepCopy function implemented in the example, which does basically what i said was the first possibility - if your object contains other object, you either have to shallow copy recursively until you get to the primitives, or do the overriden constructor thing i was talking about (or combine both). either way, modern language not having built-in deep copy function sounds pretty WTFy to me.


  • ♿ (Parody)

    @SEMI-HYBRID code said:

    either way, modern language not having built-in deep copy function sounds pretty WTFy to me.

    I've often had the same thought, but such a feature seems like an easy way to shoot yourself in the foot, especially once you get into business objects in an ORM situation with lots of references / relations to other objects. So I think that ultimately, not having an automatic way to duplicate data in your DB is probably a good thing on balance.



  • @SEMI-HYBRID code said:

    either way, modern language not having built-in deep copy function sounds pretty WTFy to me.

    But Java doesn't have a built-in deep copy func---OHHH..



  • @boomzilla said:

    @SEMI-HYBRID code said:
    either way, modern language not having built-in deep copy function sounds pretty WTFy to me.

    I've often had the same thought, but such a feature seems like an easy way to shoot yourself in the foot, especially once you get into business objects in an ORM situation with lots of references / relations to other objects. So I think that ultimately, not having an automatic way to duplicate data in your DB is probably a good thing on balance.

    Also do they worry about circular references?



  • @IMil said:

    A screw type object has to be rotated with a screwdriver (which seems quite an inefficient and slow method to me).
    You can't hammer a screw in? I wish somebody told that to my mother and grandfather...



  • @ender said:

    @IMil said:
    A screw type object has to be rotated with a screwdriver (which seems quite an inefficient and slow method to me).
    You can't hammer a screw in? I wish somebody told that to my mother and grandfather...

    Apparently all they had was a hammer. :P



  • @Mason Wheeler said:

    @ender said:

    @IMil said:
    A screw type object has to be rotated with a screwdriver (which seems quite an inefficient and slow method to me).
    You can't hammer a screw in? I wish somebody told that to my mother and grandfather...

    Apparently all they had was a hammer. :P

    Wait, so were his grandparents nailing or screwing?


  • @IMil said:

    A screw type object has to be rotated with a screwdriver (which seems quite an inefficient and slow method to me).
    People tend not to realise, but you can hammer in screws - and a bit bizarrely, they actually screw themselves into the wood when you do. Joiners will tell you that the head on a screw is only for removing it. Cabinet makers, probably less so.



  • @Sutherlands said:

    @Mason Wheeler said:

    @ender said:

    @IMil said:
    A screw type object has to be rotated with a screwdriver (which seems quite an inefficient and slow method to me).
    You can't hammer a screw in? I wish somebody told that to my mother and grandfather...

    Apparently all they had was a hammer. :P

    Wait, so were his grandparents nailing or screwing?

    Neither. It was his mother and grandfather...



  • @morbiuswilters said:

    @Sutherlands said:
    Wait, so were his grandparents nailing or screwing?
    Neither. It was his mother and grandfather...

    The question is, was it his maternal grandfather or his paternal grandfather?



  • @dhromed said:

    Because strained, swiss-cheese prosaic metaphors are the best way of getting a point across.

     

     


    Sorry for not coming up with a more original one.

    Anyhow, I apologize to the OP if it seems that I was mocking him. His question is actually quite reasonable for a person starting to learn .NET. It's his colleagues "with several years of .NET experience" who surprise me by not knowing the fundamentals.


  • Trolleybus Mechanic

    @PJH said:

    @Sutherlands said:
    Do you also use hungarian notation?
    Which? Systems or Apps?
     

    First one, then the other.



  • @Lorne Kates said:

    First one, then the other.
     

    Stir-fry until glazed, then add the spice mix, and then the meat.


Log in to reply