& versus +


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Page 1 of 2 12 LastLast
Results 1 to 15 of 21

Thread: & versus +

  1. #1
    Beginner Guest

    & versus +


    In the past, it was considered good practice to do use & for string concatenation
    rather than + because of evil type coercion. Does this still hold true for
    VB.NET, or does it not matter anymore? Does it make any difference if you're
    using Option Strict?

  2. #2
    Jonathan Allen Guest

    Re: & versus +

    Officially, we are suppose to use "&" for appending strings. I haven't
    checked to see if "+" even works, as I never use it.

    When Option Strict is on, there is no evil type coercion.

    --
    Jonathan Allen


    "Beginner" <a@b.com> wrote in message news:3bbc6c60$1@news.devx.com...
    >
    > In the past, it was considered good practice to do use & for string

    concatenation
    > rather than + because of evil type coercion. Does this still hold true for
    > VB.NET, or does it not matter anymore? Does it make any difference if

    you're
    > using Option Strict?




  3. #3
    Beginner Guest

    Re: & versus +


    "Jonathan Allen" <greywolf@cts.com> wrote:
    >Officially, we are suppose to use "&" for appending strings. I haven't
    >checked to see if "+" even works, as I never use it.


    Is that still true with VB.NET? I believe C# only supports +. So, if there
    is a difference, doesn't that mean that C# may not do string concatonations
    properly?

  4. #4
    Cali LaFollett Guest

    Re: & versus +

    > >Officially, we are suppose to use "&" for appending strings. I haven't
    > >checked to see if "+" even works, as I never use it.

    >
    > Is that still true with VB.NET? I believe C# only supports +. So, if there
    > is a difference, doesn't that mean that C# may not do string

    concatonations
    > properly?


    Yes, you can use the "+" for concatenations. It works just fine now as long
    as you use Option Strict. As Jonathan mentioned, I also mainly use the "&"
    since that my fingers are used to typing. :-)

    Cal



  5. #5
    Gregor R. Peisker Guest

    Re: & versus +

    Hi,

    > >Officially, we are suppose to use "&" for appending strings. I haven't
    > >checked to see if "+" even works, as I never use it.


    > Is that still true with VB.NET? I believe C# only supports +. So, if there
    > is a difference, doesn't that mean that C# may not do string concatonations
    > properly?


    C# is a different language, thus it's "+" operator may have different semantics
    than the one in VB.NET. If you use strings as parameters, C# will concatenate
    them; if your operands are numbers, it will add them. You can't mix both in C#
    anyway.

    Gregor




  6. #6
    Jonathan Allen Guest

    Re: & versus +

    > Is that still true with VB.NET?

    There is a MS document that compares the operators in all the .Net
    languages. In it, the "&" symbol is explicitly listed as the string
    concatenation operator for VB.

    > I believe C# only supports +.


    Like C, they use the "&" symbol as the bitwise operator "And". So they have
    to use the addition operator for concatenation.

    --
    Jonathan Allen


    "Beginner" <a@b.com> wrote in message news:3bbc84d7$1@news.devx.com...
    >
    > "Jonathan Allen" <greywolf@cts.com> wrote:
    > >Officially, we are suppose to use "&" for appending strings. I haven't
    > >checked to see if "+" even works, as I never use it.

    >
    > Is that still true with VB.NET? I believe C# only supports +. So, if there
    > is a difference, doesn't that mean that C# may not do string

    concatonations
    > properly?




  7. #7
    Jonathan Allen Guest

    Re: & versus +

    > Yes, you can use the "+" for concatenations.

    I would rather it didn't.

    --
    Jonathan Allen


    "Cali LaFollett" <cali@no-spam-please-visionized.com> wrote in message
    news:3bbc86aa@news.devx.com...
    > > >Officially, we are suppose to use "&" for appending strings. I haven't
    > > >checked to see if "+" even works, as I never use it.

    > >
    > > Is that still true with VB.NET? I believe C# only supports +. So, if

    there
    > > is a difference, doesn't that mean that C# may not do string

    > concatonations
    > > properly?

    >
    > Yes, you can use the "+" for concatenations. It works just fine now as

    long
    > as you use Option Strict. As Jonathan mentioned, I also mainly use the "&"
    > since that my fingers are used to typing. :-)
    >
    > Cal
    >
    >




  8. #8
    Cali LaFollett Guest

    Re: & versus +

    > I would rather it didn't.

    I agree completely. Nothing like mixing up more standards huh? <g>

    Cal



  9. #9
    Cali LaFollett Guest

    Re: & versus +

    > There is a MS document that compares the operators in all the .Net
    > languages. In it, the "&" symbol is explicitly listed as the string
    > concatenation operator for VB.


    Kinda funny too since if you look at some of the sample code for strings,
    they use "+". I wish MS could stick to their own docs as a lot of people
    will look at the sample code to figure out the correct way to do things.
    Although, with Option Strict on, it shouldn't make much of a difference, it
    would still be nice to follow a standard.

    Cal



  10. #10
    Jonathan Allen Guest

    Re: & versus +

    Wish List: Option Sanity

    This option would turn off all backwards compatibility options in the
    IDE/Compiler. A partial list includes...

    The + operator can only be used for Addition.

    The On Error syntax will not be allowed.

    While/Wend will be auto-corrected to Do/Loop instead of While/End While

    Redundant X=Nothing lines will be erased.

    Dim X() As Integer is not allowed. The data type is "Integer()" not
    "Integer". The former is a reference type derived from Array, the other a
    structure.

    In addition, it will make the smarty-pants IDE no so lazy...

    When you see "X cannot be implicitly converted to type Y", the grammar
    checker offers to add the CType call for you.

    When viewing a string, inner quotes are distinguished from outer quotes...
    S = "He said, ""The pigs are flying!"""
    ....when not being edited becomes...
    S = "He said, "The pigs are flying!""
    ....where the outer quotes are bold and in a different color from the string
    contents.

    Both ...
    Dim X (5) as Integer
    .... and ...
    Dim X as Integer(5)
    .... will be displayed as...
    Dim X As Integer(0 To 5)
    .... with the "0 To" part in gray. That is, until they fix it so that we can
    specify lower bounds again.



    --
    Jonathan Allen


    "Cali LaFollett" <cali@no-spam-please-visionized.com> wrote in message
    news:3bbc9d19$1@news.devx.com...
    > > I would rather it didn't.

    >
    > I agree completely. Nothing like mixing up more standards huh? <g>
    >
    > Cal
    >
    >




  11. #11
    Jonathan Allen Guest

    Re: & versus +

    > Kinda funny too since if you look at some of the sample code for strings,
    > they use "+". I wish MS could stick to their own docs as a lot of people
    > will look at the sample code to figure out the correct way to do things.


    Looking back, it seems like every version of Basic has countless examples of
    how not to write a program. The documentation itself is great, but you would
    think by now they would use real programmers to write the example sections.

    --
    Jonathan Allen


    "Cali LaFollett" <cali@no-spam-please-visionized.com> wrote in message
    news:3bbc9db5$1@news.devx.com...
    > > There is a MS document that compares the operators in all the .Net
    > > languages. In it, the "&" symbol is explicitly listed as the string
    > > concatenation operator for VB.

    >
    > Kinda funny too since if you look at some of the sample code for strings,
    > they use "+". I wish MS could stick to their own docs as a lot of people
    > will look at the sample code to figure out the correct way to do things.
    > Although, with Option Strict on, it shouldn't make much of a difference,

    it
    > would still be nice to follow a standard.
    >
    > Cal
    >
    >




  12. #12
    Cali LaFollett Guest

    Re: & versus +

    > Looking back, it seems like every version of Basic has countless examples
    of
    > how not to write a program. The documentation itself is great, but you

    would
    > think by now they would use real programmers to write the example

    sections.

    May want to add that one to your wish list you posted earlier! :-)

    Don't think you will get that one though! <vbg>

    Cal



  13. #13
    Jonathan Allen Guest

    Re: & versus +

    > May want to add that one to your wish list you posted earlier! :-)

    The documentation uses filters instead of options. But I wouldn't be against
    a filter called "The stuff I actually want to see."


    --
    Jonathan Allen


    "Cali LaFollett" <cali@no-spam-please-visionized.com> wrote in message
    news:3bbca60a$1@news.devx.com...
    > > Looking back, it seems like every version of Basic has countless

    examples
    > of
    > > how not to write a program. The documentation itself is great, but you

    > would
    > > think by now they would use real programmers to write the example

    > sections.
    >
    > May want to add that one to your wish list you posted earlier! :-)
    >
    > Don't think you will get that one though! <vbg>
    >
    > Cal
    >
    >




  14. #14
    Dan Barclay Guest

    Re: & versus +

    On 4 Oct 2001 07:04:16 -0700, "Beginner" <a@b.com> wrote:

    >
    >In the past, it was considered good practice to do use & for string concatenation
    >rather than + because of evil type coercion. Does this still hold true for
    >VB.NET, or does it not matter anymore? Does it make any difference if you're
    >using Option Strict?


    The "+" operator is the original "native" operator for concatenation.
    the "&" was added when they introduced type coercion that allowed you
    to mix numeric and string data types. This was bad practice in the
    first place and I *strongly* recommend you avoid mixing types.

    So long as you use straightforward expressions (don't mix data types),
    the + operator is fine. Many of us still use it as our default (only)
    concatenation operator.

    Dan
    Language Stability is a *feature* I wish VB had!
    (#6)

  15. #15
    Guest

    Re: & versus +


    "Jonathan Allen" <greywolf@cts.com> wrote in message news:3bbca21e@news.devx.com...
    > Wish List: Option Sanity


    You have my vote for that.

    Jens



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center