MVC Hungarian
-
It annoys me having to name one class PersonModel, one PersonView, and PersonController, but that seems like the only sensible way to avoid aliasing. If someone comes up with a better way could they let me know, please?
-
Disambiguate via namespaces? Honestly I don't think Hungarian in this case is bad - it's bad when you're repeating language-level information, not semantic ones.
-
The only other thing I could think of would be to make it generic, so
Model<Person>
, etc.
-
Does c# allow you to import a namespace? java doesn't. This would be a solved problem if I could refer to my models by [mM]odel.Person instead of needing the full {org}.{appname}.{package}.Person
-
Does c# allow you to import a namespace?
Yes. The thing you're describing is 100% supported.
-
Even better still, C# allows you to alias class names! Oh wait, this isn't the Terrible Ideas thread...
-
Yes, all you need to do is that for each code file, when you first type out the class name, you have to click the hint VS gives you to import the namespace.
They're I think hierarchical too, so you can
using MyBusiness.MyProject.Some.Other.Crap
and still be able to disambiguate betweenModels.Person
andViews.Person
.But I'd just go with Hungarian-ish.
-
Aliasing is actually kinda useful when your coding standard is just to import everything, and you end up with a conflict somewhere at the top of the chain, so you either do
using ViewPerson = ....Person
or type everything from the point of divergence each time.
-
Sadly, I've encountered this being useful at times. It should be avoided whenever possible, but sometimes...
These days, you can even do
using static System.Math;
and then doRound(0.93845739)
.
-
These days, you can even do using static System.Math; and then do Round(0.93845739).
Why do I imagine that's something a VB.NET developer would spew all over a C# code base? I wonder if Sonar has a quality rule about that...
-
It's more a C++ dev thing. They can do even weirder things, like do that to something that isn't static. I hope C# stays firm on static only.
One thing they may do in C#7:
public new {string Name, int Id, object HorribleThing} FunctionName(); // Probably have the syntax slightly wrong
Essentially, it would compile to a tuple with named properties. It scares me, but would be better than tuples are now.
-
Did Java remove
import a.name.space.*;
when I wasn't looking?
-
import a namespace
make it generic
Actually, now I think about it, I tried this with discouser, except I still ended up disconaming them.Iirc the issue was that it got too weird referring to something as a.b in one file and just b in another. Plus there's convention to be aware of. Sorry for wasting everybody's time on a wild goose chase.
-
except I still ended up disconaming them
Fuck. Now that I look at it, I didn't even do that. I've got a class with one name sitting in a file with a different name. Honestly, I am the worst programmer.
-
Essentially, it would compile to a tuple with named properties.
Which is bound to throw someone off sometime, because it really looks like it should compile to an anonymous type.
-
In C#, doing a single
importusing inserts an arbitrary number of names into the namespace.
In Java, doing a single import inserts one name into the namespace, unless it has*
at the end.
In Go, doing a single import inserts one name into the namespace, unless it has.
at the beginning (import package namespace into current namespace) or_
at the beginning (import for side effects).
In Cool, doing a single import crashes the compiler.
-
-
There are a bunch of keywords that Cool defines and then doesn't use for anything. Here's a full list, but ruined by Discourse:
abstract
catch
do
final
finally
for
forSome
implicit
import
lazy
object
package
private
protected
requires
return
sealed
throw
trait
try
type
val
with
yield
These all get parsed as ILLEGAL tokens. For example,
lazy forSome with val
is parsed asILLEGAL ILLEGAL ILLEGAL ILLEGAL
Also,
native
, but that's allowed for specific class+method/field/whatever combinations that are defined in the standard library.