Which is looser - a longer or shorter syntax?

I'm trying to create my first free interface, and I was just wondering what the other poeple considered more fluently and which one would they rather use?

Check.Field().Named("est").WithValueOf("sdsd").IsNotNull() Check.Field("est").WithValueOf("sdsd").IsNotNull() Check.Field("est").WithValue("sdsd").IsNotNull() 

Cheers Anthony

+4
source share
5 answers

The latter is unequivocal:

 Check.Field("est").WithValue("sdsd").IsNotNull() 
+4
source

I agree:

 Check.Field("est").WithValue("sdsd").IsNotNull() 

As short as possible, still making sense.

Avoid noise words such as .as. .of. .and. .in. .as. .of. .and. .in. if they do not add contextual meaning. I have seen some nice interfaces that do this, and it doesn't add anything useful except more input and more hoops for the application to jump over when it runs.

+3
source

Or, to simulate some collections, use the Item Property :

 Check["est"].WithValue("sdsd").IsNotNull() 

Some may also say that you should just use .IsNull () and deny the whole expression like this, but that it’s β€œsix and a half dozen”:

 !Check["est"].WithValue("sdsd").IsNull() 
0
source

Another option could be:

 Check.Field("est").IsNotNull("sdsd") 

Something like LINQ FirstOrDefault, called by a predicate instead of filtering, and then calling FirstOrDefault.

0
source

What is Check ? I suspect that this is not necessary at all. I understand what you are trying to do, but remember that the expression you are trying to build will still probably be in the if statement. With that in mind, think about how to read β€œif check is X”. Not too good, IMHO. Also, what does the Field function do to resolve this name? Do you have something else that you could provide better (perhaps an extension method on some basic type?)

0
source

All Articles