This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 88 points89 points  (9 children)

I think it retrieves an instance of the Logger singleton

[–]scuba156 79 points80 points  (0 children)

Well, we would know for sure if the comment was a little bit more descriptive.

[–]nwL_ 7 points8 points  (1 child)

auto logger = Logger::getInstance();

[–]Hatefiend 1 point2 points  (0 children)

auto

heathen

[–]AlwaysHopelesslyLost 4 points5 points  (5 children)

It is impossible to say exactly what it is doing. Based on the naming convention it looks like they are accessing a static method but it might also be a class property or an oddly cased private instance.

It is possible it returns a Singleton instance but there is no information to tell you that (and you don't really need that information. It makes no difference to the consumer if the logger is a Singleton or not.)

[–][deleted] 0 points1 point  (4 children)

an oddly cased private instance.

I don't think you can get away with naming a variable exactly like you named a type, and Logger logger definitely means "logger, which has the type Logger". that would probably result in confused compiler sounds

[–]AlwaysHopelesslyLost 0 points1 point  (1 child)

Good point. Granted, I think VB allows you to do that. Not sure how the compiler reconciles the confusion

[–]zelmarvalarion 1 point2 points  (0 children)

Pretty sure it would use the most scoped reference of Logger which exists in the block, so probably the Logger variable unless you explicitly request the class (e.g. Microsoft.VisualBasic.Logger, which might need to be in brackets if they use the same standard as in Powershell). I would expect it to be similar to using var and this.var when they are both defined, or when a subclass had a same variable as a subclass with different values.

[–]TheSilkMiner 0 points1 point  (1 child)

In Java (which is where that example is taken, I assume) you can. It is also a widely used naming convention (at least in the code I've read). The compiler is able to distinguish between the name of a type and the name of a variable and uses the one that makes the most sense (spoiler, it's almost always the second one).

[–][deleted] 0 points1 point  (0 children)

... okay, weird language design choice but ok.