Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Dr Monkeysee
Oct 11, 2002

just a fox like a hundred thousand others
Nap Ghost

ShaunO posted:

Use var everywhere, IMO.

var life 4 eva

Adbot
ADBOT LOVES YOU

Dr Monkeysee
Oct 11, 2002

just a fox like a hundred thousand others
Nap Ghost
Null propagation yesssssssss one more battle won in the war against null.

Dr Monkeysee
Oct 11, 2002

just a fox like a hundred thousand others
Nap Ghost
Are you stuck with having to use the database directly? Because it sounds like you're trying to implement full-text search which you'd be better off using a tool that already does this like Lucene or elasticsearch, or an RDBMS that supports full-text search (I believe postgres has recently added support for this). They will support stemming, pluralization, etc out of the box. This is a problem with a huge amount of edge cases and natural language-aware logic that is gonna be pretty hard to get right yourself.

Dr Monkeysee fucked around with this message at 04:31 on Jan 8, 2015

Dr Monkeysee
Oct 11, 2002

just a fox like a hundred thousand others
Nap Ghost
Run two instances of VS, one debugging the website and one debugging the WCF service.

Dr Monkeysee
Oct 11, 2002

just a fox like a hundred thousand others
Nap Ghost

Cuntpunch posted:

At happy hour with a colleague recently we discussed how nice it would be to have a Java Extension for Linq Querying.

You mean Java 8 streams are or you referring to something like the weird sql syntax? Or IQueryable?

Dr Monkeysee
Oct 11, 2002

just a fox like a hundred thousand others
Nap Ghost

22 Eargesplitten posted:

What's the point of a getter and setter if the syntax for calling them is the same as getting the variable if it were a public variable? I thought the point of getters and setters was to make sure that nothing outside that class could access the variable without going through a specific method call.

Also, why can't I set a variable to be private and then make the getters and setters public? Coming from Java, this whole thing seems weird.

It feels like no one addressed your *specific* concern here so I'll throw in my two cents:

Properties in C# are syntactic sugar over the exact same get/set pattern you use in Java. So the following code is equivalent:

C# code:
class Butt
{
    private int poop;

    public int Poop
    {
        get { return poop; }
        set { poop = value; }
    }
}
Java code:
class Butt {
    private int poop;

    public int getPoop() {
        return poop;
    }

    public void setPoop(int value) {
        poop = value;
    }
}
There's your "private field + public getters and setters". They're exactly the same pattern, it's just more succinct in C#.

When you use them the C# code is exactly equivalent to the Java code (in fact the intermediate bytecode language is virtually identical to the Java code):

C# code:
var b = new Butt();
b.Poop = 4;              // exactly the same as b.setPoop(4);
int p = b.Poop;        // exactly the same as int p = b.getPoop();
C# uh.... 4 I think? introduced additional syntax for auto properties. It is often the case that a getter and setter are trivial (like in the examples above) so the C# compiler says hey I can generate this code for you. So with auto properties the above example becomes:

C# code:
class Butt
{
    public int Poop { get; set; }
}
Again, to stress this, this is *exactly the same* as the code in our first C# example and exactly equivalent to the get/set pattern of Java. You're just relying on the compiler to generate the boilerplate for you.

Finally in C# 6 they introduced an additional bit of syntax. Sometimes you want to initialize your property to something other than the default. Autoproperties won't let you do that because you don't control what the name of the underlying field is (it's auto-generated) so there's no hook to initialize it. So now you have "auto-implemented properties".

C# code:
class Butt
{
    public int Poop { get; set; } = 12;
}
This is *exactly the same* as the following code:

C# code:
class Butt
{
    private int poop = 12;

    public int Poop
    {
        get { return poop; }
        set { poop = value; }
    }
}
Why go to all this trouble? Because writing boilerplate is boring and the C# team has really embraced the approach of "let the compiler write the boring code for you". Java has generally relied on tooling to do that for you (e.g. code-generation snippets in Eclipse). Same problem, different solutions.

The point is these are all equivalent. C# properties are just syntax over normal get/set in Java. Behaviorally it's exactly the same.

Dr Monkeysee
Oct 11, 2002

just a fox like a hundred thousand others
Nap Ghost

ljw1004 posted:

The question of "which ones are run asynchronously" is pretty unpredictable...

Seems like there's a much simpler answer to this question which is: as the caller you'd have to know which statements throw before the first await in the method body and which statements throw after the first await in the method body.

Which is... madness. That would be completely unworkable the second you hit an async method that isn't your own code.

Dr Monkeysee
Oct 11, 2002

just a fox like a hundred thousand others
Nap Ghost
You guys are using "inheritance" in two ways. Static members are part of the inheritance chain for the purposes of symbol lookup, which is why you can call parent class static members from a child class (or even from an instance of a class). Static members are not overridable and therefore don't participate in the dynamic-dispatch portion of inheritance. Hence referencing a static member from a child class isn't really invoking that child class as far as the CLR is concerned.

Adbot
ADBOT LOVES YOU

Dr Monkeysee
Oct 11, 2002

just a fox like a hundred thousand others
Nap Ghost
I agree this is surprising behavior though. It makes perfect sense when explained but seems extremely easy to overlook when you're just banging out code.

In general you just don't want to mix static data and class inheritance if you can help it.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply