Visual Studio...


  • FoxDev

    @boomzilla said:

    Eh...OK, I'm not completely clear on what using does. Looks similar to C++...it doesn't actually add any new stuff into your...um...local context, it just makes it so you don't type the namespace. There's no equivalent thing in Java.

    Really? How do you import namespaces then? 😛

    Of course, if you're talking about using {}, then AFAIK there's no Java equivalent.
    @blakeyrat said:

    @RaceProUK said:
    Doesn't that same menu also offer to create a skeleton class for you?

    Well yes, but that's not the feature anybody's been talking about in this entire long thread.

    True, but it's part of the same menu, which is why you get a menu instead of VS auto-adding the using statement. I think it also gives you a choice between adding the using and adding the fully-qualified name.



  • Ah, checked and it's mapped to Shift-Alt-F10 as well as Ctrl-. on my box; however, I suspect it simply isn't functional for native code (which is all I work on).



  • @dstopia said:

    I'm not sure because I'm not familiar enough with C# but I just see it as an analog of import.

    C# has two concepts, it has "references" which is basically which libraries your project can call on. I assume that's the equivalent to "import".

    using just tells the compiler which namespaces it should check to resolve class names at any given time. Before you can "use" a namespace, you have to include it in the project as a "reference". (Interestingly, in partial classes, each part has its own using list. Figure that one out.)

    "import" might actually perform both functions (I'm pretty sure it does in Python, for example.)



  • @blakeyrat said:

    C# has two concepts, it has "references" which is basically which libraries your project depends on. I assume that's the equivalent to "import".

    Actually, it works the same way in Java, the libraries you link to is a separate concept from the namespace your classes resolve to. As long as the fully qualified package path is spelled out, you can reference any class in the standard Java library without importing it as long as you link to it.


  • ♿ (Parody)

    @RaceProUK said:

    Really? How do you import namespaces then?

    I would start by using a language that uses namespaces.



  • @dstopia said:

    Actually, it works the same way in Java, the libraries you link to is a separate concept from the namespace your classes resolve to. As long as the fully qualified package path is spelled out, you can reference any class in the standard Java library without importing it as long as you link to it.

    "import" is a really bad word to mean that.

    But ok.

    I should mention in C#, "references" includes third-party and such, not just standard library references. But in an average program, 90% of them are standard library references.



  • I'm afraid to fuck up here since I don't have a formal education in programming, but I always assumed that that's what packages represent in Java...?


  • ♿ (Parody)

    @blakeyrat said:

    "import" is a really bad word to mean that.

    Eh...it imports symbols from a class or namespace to be used in the current file.


    Filed Under: Today on the daily what the sematics,Tune in next week for quit vs exit


  • ♿ (Parody)

    @dstopia said:

    I'm afraid to fuck up here since I don't have a formal education in programming, but I always assumed that that's what packages represent in Java...?

    Eh, sort of. I'm assuming that C# has a similar concept? And namespaces are another level. But I don't know. I know they're very different in C++.



  • @boomzilla said:

    Eh...it imports symbols from a class or namespace to be used in the current file.

    But nothing gets moved, so there's no import. Import is moving data from one place to another. It's not "oh hey, you can use this set of names now".

    Not to say "using" is a great term, either. But much better than "import".



  • Of course, yeah. For the purposes of learning more about C# I googled a bit and now I realize that there's no access-level restriction in C# namespaces, which I guess is a pretty big difference from Java packages.


  • FoxDev

    @boomzilla said:

    I would start by using a language that uses namespaces.

    …you're really not familiar with C#, are you? It has namespaces; they work more-or-less exactly like Java namespaces.


  • ♿ (Parody)

    @blakeyrat said:

    Import is moving data from one place to another

    :rolleyes:

    It's importing symbols into the current context.

    https://youtu.be/Rwat_47tU6o


  • ♿ (Parody)

    @RaceProUK said:

    …you're really not familiar with C#, are you?

    What was your first clue?

    @RaceProUK said:

    It has namespaces; they work more-or-less exactly like Java namespaces.

    So it doesn't have them? Actually, I'm going to take that as an admission that you're not really familiar with Java.

    I mean, it has the concept of namespaces, but not an actual keyword, etc, like C#.


  • FoxDev

    @boomzilla said:

    I mean, it has the concept of namespaces, but not an actual keyword, etc, like C#.

    Java uses the directory structure to identify namespaces, so it doesn't need a keyword; AFAICT, that's the only practical difference



  • @boomzilla said:

    It's importing symbols into the current context.

    But it's not. There's no movement of data. The symbols don't "go" anywhere.


  • ♿ (Parody)

    @RaceProUK said:

    Java uses the directory structure to identify namespaces, so it doesn't need a keyword; AFAICT, that's the only practical difference

    Sort of.

    @blakeyrat said:

    But it's not.

    LIES.

    @blakeyrat said:

    There's no movement of data. The symbols don't "go" anywhere.

    :rolleyes:



  • @dstopia said:

    Of course, yeah. For the purposes of learning more about C# I googled a bit and now I realize that there's no access-level restriction in C# namespaces, which I guess is a pretty big difference from Java packages.

    True; but everything is private by default in C# so you don't leak classes that were supposed to be private/internal accidentally. It's not as simple in C#, but makes more sense, IMO.



  • @blakeyrat said:

    The symbols don't "go" anywhere.

    Did someone say Go?

    I have a file that starts with this:

    package bit
    
    import (
            "errors"
            "fmt"
            "io"
    
            "github.com/BenLubar/bit/bitio"
    )
    

    which is equivalent to this:

    package bit
    
    import "errors"
    import "fmt"
    import "io"
    import "github.com/BenLubar/bit/bitio"
    

    Basically it says "bind this import path to its package name". If I had said import blakeyrat "fmt", it would use blakeyrat as the package name for the package containing Println, Sprintf, Fprintf, etc.

    If I don't use any symbols from a package I import, that's a compile-time error. I use a tool named goimports, which runs automatically when I save in my editor. It adds/removes/organizes my imports for me unless there's an ambiguity. It also formats my code (I can be sloppy and it'll fix it for me).



  • @dstopia said:

    TWO HUNDRED AND FIFTY US DOLLARS

    https://www.youtube.com/watch?v=BOHqG1nc_tw



  • This post is deleted!


  • @boomzilla said:

    @blakeyrat said:
    There's no movement of data. The symbols don't "go" anywhere.

    :rolleyes:


    Blakey has a little bit of a point actually. Contrast to something that C++ does (confusingly for this discussion) with the using keyword:

    namespace First {
        struct S {};
    }
    
    namespace Second {
        using First::S;
    }
    
    Second::S s;
    

    using First::S doesn't merely make First::S available for unqualified use in Second, but it actually imports -- in the sense that Blakey means -- the name S within Second. If you try to declare a struct S {}; in Second after the using declaration, you'll get an error for a duplicate definition.

    This feature can actually be quite helpful on occasion.

    (And of course, because this is C++, I'm pretty sure that the above does not apply to using namespace; in other words, if you replace First::S with using namespace First, it shouldn't create a Second::S name. I'm not 100% sure because GCC accepts it even in that case -- but I think it's wrong. It does get another aspect right -- if you declare struct S {}; after the using namespace First directive, you do not get a duplicate declaration error.)


  • ♿ (Parody)

    @EvanED said:

    Blakey has a little bit of a point actually.

    Only if you have a limited grasp of English and refuse to accept connotations of words that you aren't already familiar with.

    @EvanED said:

    using First::S doesn't merely make First::S available for unqualified use in Second, but it actually imports -- in the sense that Blakey means -

    No, that imports in the sense that I mean. Blakey is saying that's not importing at all because no data moved anywhere.



  • @boomzilla said:

    No, that imports in the sense that I mean.
    No, it doesn't. import in Java doesn't affect the externally-visible names of a file. You can add 100 imports to a file and it won't affect anything external to it.


  • ♿ (Parody)

    @EvanED said:

    No, it doesn't. import in Java doesn't affect the externally-visible names of a file. You can add 100 imports to a file and it won't affect anything external to it.

    Meh. I was talking about Java, where "namespaces" work differently, and what you talked about was still closer to what I was saying and GIBBERISH in blakeyish. You just went a bit farther with the import conceptGIBBERISH.



  • OK, to answer some of the things that came up in this thread:

    • Visual Studio's References are similar to Java's Classpath, with a special note that Java's classpath can contain directories of class files in addition to packaged code units.
    • C#'s using directive is similar to Java's import. Their purpose is to use shorter names for things and each one has its own optional stuff you can use, such as C#'s using aliasing and Java's import static.
    • C#'s using statement is similar to Java's try-with-resources.

    Eclipse has the option to add imports in its Quick Fix menu, which can be accessed 3 ways:

    1. Move your mouse cursor over the unrecognized class and wait about 1 second.
    2. Press Ctrl+1
    3. Right click the class in question and choose Quick Fix from the menu.

    It looks like this:

    (Note: I had to hit F2 to focus it so I could use the Snipping Tool's Ctrl+PrintScreen without it vanishing)

    You can see it offers to add an import for me, create a new class/interface, or change it to a similarly named class.



  • @RaceProUK said:

    Java uses the directory structure to identify namespaces, so it doesn't need a keyword; AFAICT, that's the only practical difference

    That sounds like the worst idea.

    "Hey boss, the project was getting a bit cluttered, so I moved the CSV-related stuff to a directory."

    "Ok, have fun REFACTORING EVERYTHING BECAUSE NOW THE NAMESPACE CHANGED YOU SUCKER!"

    "... ok I'll move it back, cluttered it is!"


  • ♿ (Parody)

    @blakeyrat said:

    "Ok, have fun REFACTORING EVERYTHING BECAUSE NOW THE NAMESPACE CHANGED YOU SUCKER!"

    Like other refactoring, the IDE (Eclipse, in this case) takes care of this for me and updates the import statements. I'm not seeing the problem here.



  • @boomzilla said:

    Like other refactoring, the IDE (Eclipse, in this case) takes care of this for me and updates the import statements. I'm not seeing the problem here.

    (Presumably; I don't use Eclipse) only if all the code using the library is loaded at the same time as the library itself. And if they're all even present on the machine you made the library change on.

    You never, in the Java world, have a library in one solution that's used in a different solution?

    And note that VS ties the namespace to directory when you create the class by default, because that bit of the idea is good. The bad part is requiring it to be the same as the directory. Unless your goal is to make refactoring of the "meh, I'll just put all these classes in a subdirectory"-type impossible. In which case, good work!



  • @dstopia said:

    I googled a bit on the matter just to prove I'm not the WTF here, and I was pointed to ReSharper, which is a plugin that costs TWO HUNDRED AND FIFTY US DOLLARS. What?!

    250 for Ultimate, 120 for standard, free if you can convince them you're open source, I believe. And Ultimate is only for people who want all the Jetbrains products, which isn't most people.

    Also, I'd suggest checking VS2015, because while I haven't tested it thoroughly, they built in Resharper's alt+enter helper things, which may make this easier.


  • ♿ (Parody)

    @blakeyrat said:

    You never, in the Java world, have a library in one solution that's used in a different solution?

    I do. I have lots of external jars. It's happened occasionally when I've updated versions that I needed to make some changes in the code that uses it. Like any other API changes.

    @blakeyrat said:

    The bad part is requiring it to be the same as the directory.

    Eh...consistency vs flexibility. I can see pros and cons both ways, but not enough to get excited about.



  • @blakeyrat said:

    But it's not. There's no movement of data. The symbols don't "go" anywhere.

    There is more than one definition of that word : http://dictionary.reference.com/browse/import



  • Of course not, that would just be silly.

    Personally, I don't pay for anything!



  • @powerlord said:

    each one has its own optional stuff you can use, such as C#'s using aliasing and Java's import static.

    The new version of C# includes using static, in fact. This may be a nice feature. But not, imo, nicer than being able to create a property like this: public string FullName => FirstName + LastName;


  • Java Dev

    @blakeyrat said:

    The bad part is requiring it to be the same as the directory.

    Yeah, cause you end up with 4 levels of single directories that you can't tab complete immediately because there's a hidden VCS subdir as well.


  • :belt_onion:

    TRWTF is your VCS subdirectory having any effect on your IDE...



  • Why are you not using git or hg?


  • Java Dev

    @sloosecannon said:

    TRWTF is your VCS subdirectory having any effect on your IDE...

    You're quite right - fixed (with bind 'set match-hidden-files off' in my bash environment)

    @ben_lubar said:

    Why are you not using git or hg?

    Not up to me. We're stuck with a system that was built in the mid-nineties to handle a 100+kloc codebase that took 26 hours to build.


  • kills Dumbledore

    @Magus said:

    But not, imo, nicer than being able to create a property like this: public string FullName => FirstName + LastName;

    public string fullName
    {
        get{return firstName + lastName;}
    }
    


  • @Magus said:

    public string FullName => FirstName + LastName;

    Hungary and Japan might want to talk to you about that ...


  • 🚽 Regular

    Not to mention people who care about spaces between names.



  • Maybe FirstName and LastName are a custom type with an overloaded + operator, which adds a space, and then they get implicitly converted to string. Now, which way was that bad ideas thread?


  • BINNED

    Ooooh! Nonono, we can do better! It can be locale aware and actually return values in proper order, depending on that.

    Wait, now it's starting to make sense, actually. Well, apart from overloading + instead of making it a proper method, that is.



  • Or you could just, you know, Ctrl+Shift+O


Log in to reply