Visual Studio...
-
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 youimport
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 theusing
statement. I think it also gives you a choice between adding theusing
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).
-
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 ownusing
list. Figure that one out.)"import" might actually perform both functions (I'm pretty sure it does in Python, for example.)
-
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
import
ing it as long as you link to it.
-
Really? How do you import namespaces then?
I would start by using a language that uses namespaces.
-
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...?
-
"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
-
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++.
-
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.
-
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.
-
Import is moving data from one place to another
It's importing symbols into the current context.
I'M LOST! – 00:42
— transientfoible
-
…you're really not familiar with C#, are you?
What was your first clue?
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#.
-
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
-
It's importing symbols into the current context.
But it's not. There's no movement of data. The symbols don't "go" anywhere.
-
Java uses the directory structure to identify namespaces, so it doesn't need a keyword; AFAICT, that's the only practical difference
Sort of.
But it's not.
LIES.
There's no movement of data. The symbols don't "go" anywhere.
-
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.
-
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 useblakeyrat
as the package name for the package containingPrintln
,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).
-
-
This post is deleted!
-
@blakeyrat said:
There's no movement of data. The symbols don't "go" anywhere.
Blakey has a little bit of a point actually. Contrast to something that C++ does (confusingly for this discussion) with theusing
keyword:namespace First { struct S {}; } namespace Second { using First::S; } Second::S s;
using First::S
doesn't merely makeFirst::S
available for unqualified use inSecond
, but it actually imports -- in the sense that Blakey means -- the nameS
withinSecond
. If you try to declare astruct S {};
inSecond
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 replaceFirst::S
withusing namespace First
, it shouldn't create aSecond::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 declarestruct S {};
after theusing namespace First
directive, you do not get a duplicate declaration error.)
-
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.
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.
-
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 100import
s to a file and it won't affect anything external to it.
-
No, it doesn't.
import
in Java doesn't affect the externally-visible names of a file. You can add 100import
s 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'simport
. Their purpose is to use shorter names for things and each one has its own optional stuff you can use, such as C#'susing
aliasing and Java'simport static
. - C#'s
using
statement is similar to Java'stry
-with-resources.
Eclipse has the option to add imports in its Quick Fix menu, which can be accessed 3 ways:
- Move your mouse cursor over the unrecognized class and wait about 1 second.
- Press Ctrl+1
- 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.
-
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!"
-
"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.
-
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!
-
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.
-
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.
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.
-
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!
-
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;
-
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.
-
TRWTF is your VCS subdirectory having any effect on your IDE...
-
Why are you not using git or hg?
-
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)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.
-
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;} }
-
public string FullName => FirstName + LastName;
Hungary and Japan might want to talk to you about that ...
-
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?
-
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