With - End with block in C#

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Shawn B.

    #31
    Re: With - End with block in C#

    I program windows apps as a hobby in x86 asm. On another note, I program
    SNES (16-bit 65c02) in assembly and the original 8-bit NES in asm. But I
    enjoy (as a hobby) win32 programming in asm. Nothing I do requires it. But
    I do it because I enjoy making large business applications that consume
    about 30MB in C++/or VB, but 300k in asm.


    Thanks,
    Shawn



    "Alvin Bruney" <vapordan_spam_ me_not@hotmail_ no_spamhotmail. com> wrote in
    message news:uRO52G1nDH A.2628@TK2MSFTN GP10.phx.gbl...[color=blue]
    > Out of curiousity. What do you do that requires assembler?
    >
    > I have a mental block to that language. It reminds me of D's and E's in
    > compsci. Forced to learn it to master the debugger, but still hate its[/color]
    guts.[color=blue]
    >
    > --
    >
    >
    > -----------
    > Got TidBits?
    > Get it here: www.networkip.net/tidbits
    > "Shawn B." <leabre@html.co m> wrote in message
    > news:uPtwFN0nDH A.2964@tk2msftn gp13.phx.gbl...[color=green]
    > > Why? I"ve never had a problem doing so. It's a great conveniece and[/color][/color]
    have[color=blue][color=green]
    > > never in 7 years working with VB suffered a single lost second of
    > > productivity as a result of its presence. I never "rely" on it, but I[/color][/color]
    do[color=blue][color=green]
    > > take advantage of the features a tool offers as they are there for a[/color]
    > reason.[color=green]
    > > I've never once in my memory suffered from not being able to read code[/color]
    > that[color=green]
    > > used a "with".
    > >
    > > I hear no end to the arguments of C# developers saying how difficult it[/color][/color]
    is[color=blue][color=green]
    > > to read. In my experience, I agree, I have worked with many C# and Java
    > > developers who struggle to no end. My take? Adapt and move on. Most[/color][/color]
    VB[color=blue][color=green]
    > > programmers don't struggle as much as I've personally witnessed non VB
    > > programmers struggle with it. I'm not making a blanket statement. This[/color]
    > is[color=green]
    > > just an observation based on experience, is all.
    > >
    > > Me? I'm primarily an Assembly and C++ programmer, who gets paid well to[/color]
    > do[color=green]
    > > VB and C#. I enjoy all the features of all the languages and often pick[/color]
    > the[color=green]
    > > best tool for the job when given the choice. When not given the choice,[/color][/color]
    I[color=blue][color=green]
    > > use the features available.
    > >
    > >
    > > Thanks,
    > > Shawn
    > >
    > >
    > >
    > > "Cowboy (Gregory A. Beamer)" <NoSpamMgbworld @comcast.netNoS pamM> wrote[/color][/color]
    in[color=blue][color=green]
    > > message news:%23KFIH9Wn DHA.392@TK2MSFT NGP11.phx.gbl.. .[color=darkred]
    > > >
    > > > "Jon Skeet [C# MVP]" <skeet@pobox.co m> wrote in message
    > > > news:MPG.1a08a0 66b1cca0cc98997 6@msnews.micros oft.com...
    > > > >
    > > > > As Steve said - if you're doing a whole load of operations with a
    > > > > single object, chances are that functionality should be encapsulated
    > > > > within the object itself.
    > > >
    > > >
    > > > And, if these are properties you are setting, you should consider[/color][/color]
    > creating[color=green]
    > > a[color=darkred]
    > > > constructor that allows you to set the properties at instantiation[/color][/color]
    > rather[color=green][color=darkred]
    > > > than relying on a "with" construct.
    > > >
    > > > --
    > > > Gregory A. Beamer
    > > > MVP; MCP: +I, SE, SD, DBA
    > > >
    > > > *************** *************** *************** *************** **********
    > > > Think Outside the Box!
    > > > *************** *************** *************** *************** **********
    > > >
    > > >[/color]
    > >
    > >[/color]
    >
    >[/color]


    Comment

    • Jon Skeet [C# MVP]

      #32
      Re: With - End with block in C#

      Shawn B. <leabre@html.co m> wrote:[color=blue][color=green]
      > > 2. Which methodology is easier to maintain? I find most people that[/color]
      > heavily[color=green]
      > > use "with" in Visual Basic are pretty much being lazy.[/color][/color]
      [color=blue]
      > And if they are, so? Work smarter, not harder. It helps get the project
      > done faster. I find that most people who use it use it because it's there
      > and because it requires less typing. That's certainly why I use it. But
      > overall, I'm more productive compared to many of my peers (not because of
      > the with statement) but the with statement helps. I don't over use it, I
      > use it when it makes sense.[/color]

      While I agree with laziness being generally a good thing in programmers
      (look at Larry Wall's suggestions for a good Perl programmer), I don't
      think that "it requires less typing" is *ever* a good enough reason in
      itself for doing anything with code. Readability has to come absolutely
      first, IMO.

      Admittedly I'm not *quite* hard-working enough to always write braces
      after if blocks:

      if (x)
      {
      doSomething();
      }

      but I think in general it's a good idea.

      On the other hand, I *do* include white space for the sake of
      readability even though it means more typing. I *do* format my code for
      readability even though it means more work. I *do* comment my code even
      though it means more work. I *do* use Convert.ToStrin g(...) instead of
      ""+... even though it's slightly longer.

      Eventually, the time it takes to type the code is likely to be nearly
      insignificant in the course of the lifetime of the code - I'll usually
      spend more time thinking about it, debugging it to get it working in
      the first place, and maintaining it later on. Anything that helps with
      *those* tasks is worth much more than something that gives a short term
      typing benefit at the cost of readability - and the nature of "with"
      just reduces readability, IMO. It wouldn't be quite so bad if you could
      only have one level of "with"-ness (i.e. no nested "with"s) but I still
      don't like it in general. I'd still rather give a variable a meaningful
      name in one line and use that name in subsequent lines to make it
      explicit what's going on.

      --
      Jon Skeet - <skeet@pobox.co m>
      Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

      If replying to the group, please do not mail me too

      Comment

      • mikeb

        #33
        Re: With - End with block in C#

        Shawn B. wrote:[color=blue]
        > Its amazing how most C# programmers (in their humble opinion) view the
        > "with" as degrading or at least, not adding to, the readibility of code but
        > most VB programmers think it does. Therefore it doesn't technically work
        > either way, it's all in the perception of those who want/like/accept the
        > feature and those who don't want/like/accept the feature, but not a
        > technical one. It's a philisophical one.
        >[/color]

        However, as the "Ask a Language Designer" article
        (http://www.gotdotnet.com/team/csharp.../ask.aspx#with)
        points out, this snippet of VB code:

        With MyDataStructure .GetButton(44)
        .Text = "Hello"
        .BackColor = Color.Blue
        End With

        is equivalent to:

        Dim b as Button = MyDataStructure .GetButton(44)
        b.Text = "Hello"
        b.BackColor = Color.Blue

        which you can do in C# like so:

        Button b = MyDataStructure .GetButton(44);
        b.Text = "Hello"
        b.BackColor = Color.Blue


        So C# does really have the basic functionality of a "With" construct, it
        just has a different syntax. I agree with you that it's a philosophical
        (or probably more likely a religious) difference. I don't miss the
        "With" construct, which is easy for me, since I've never really been a
        VB programmer. But, if MS added it to C#, I wouldn't think the world
        had ended.

        For me, I think it boils down to:

        if you really, really need With/End With, use VB.NET

        if you want With/End With functionality in C#, create a
        short-lived, short-named object and deal with that.


        .... snipped old thread ...

        --
        mikeb

        Comment

        Working...