Hot answers tagged

8

I think the second variant could lead to more confusion. true should imply positive results, and false a negative result. The question in natural language is usually "Are you allowed to access the feature?", not "Are you not allowed to access the feature?". The response then is also consistent - "Yes you are allowed to access the feature" vs "Yes, you are ...


7

Let's consider both the general and the specific problem. In general the advice is usually to avoid negatives in names. The reason being: you note that it can be confusing to negate a thing; well, sometimes you have to negate a thing, and it is very confusing to negate a negative: if (!product.NotTaxable) ... Yuck. In the specific case you mention there ...


6

I hope this is just a thought experiment, because if you have a real-wold program with a thousand distinct code path selected by an int parameter, performance considerations should be way down you list of worries. It sounds completely unmaintainable. But to actually answer the question: switch is O(n). If you really want to scale you need a O(1) algorithm, ...


5

To expand on my comment I will give you my opinion on your code : Generics : I believe there is thin line between cases where generics are useful and cases where they are abused and only bring more problems. Yours is way past into the problems area. Just looking at the big generic definition rings an alarm for me. This is augmented by fact that you have ...


5

An example in C that I encounter variants of regularly: int doSomething(int argument1) { #ifdef HARDWARE_TYPE_A performAction(argument1); #else displayNotSupportedMessage(); #endif } The argument is only relevant on some platforms, but on the ones where it's not relevant my compiler will complain, and since I have warnings converted to errors it ...


4

Polymorphism with no shared interface will ONLY let you store objects in the same (strongly typed) container, not actually DO anything. You can't disptach method calls or anything like that. In your specific example, I think composition would be more appropriate, no? You already have an abstraction for a specific point in 2d space, so why woudn't you reuse ...


4

You could probably have a look at Rules Design Pattern. There is a good video also at Pluralsight, see Rules Pattern (you will need to sign in).


4

Consider these classes: class A { private int foo; public A(int f) { this.foo = f; } // works public int AddTo(A other) { return this.foo + other.foo; } // doesn't work: 'B.bar' is inaccessible due to its protection level public int AddTo(B other) { return this.foo + other.bar; } } class B { public B(int b) { this.bar = b;...


4

The first form creates an array of integers. The second form creates an array of something. The major difference is that the first variant gives you, the developer, the explicit indication of the type of objects stored in the collection. This indication will help both at the moment of writing code if you use an IDE with IntelliSense, and at the moment when ...


2

I've worked on a number of microservice projects. Inevitably companies have taken the route because their big DB approach cant scale any further. Here are my experiences/recomenations. Org. One solution per microservice. nuget packages for shared libs Development. larger teams 5-6 devs one area of functionality at a time. Refactor into a interfaced service....


2

The problem is that "MyClass.X" has a well-defined meaning, which is to call the getter on the property "X". The important thing to note is that, even though a method is being called, brackets are not required. On the other hand, when calling a regular method, such as when you call "Foo" in your example code, brackets are required to indicate that the ...


2

I know more than 30 programming languages and yet I agree with your prof. It's better to invest your time in the algorithms and approaches than in the languages per se. If Azure seems shallow to you, invest in something else. Dynamic programming, databases, machine learning, high availability, etc etc. For resume it's more important to show that you're ...


2

Assuming you will call HttpUtility.HtmlEncoded() from your extension method (otherwise it's a no-no) and also that you will use a meaningful name to your method (otherwise you will just make code less clear). Given: string someText = "This is some text"; Let's compare: string htmlEncoded1 = someText.ToHtmlEncodedString(); string htmlEncoded2 = ...


2

The two subclasses does not have any interface in common, so why you do you want to have them inherit from a common class in the first place? The Location class does not provide you any benefit as far as I can tell. To me it would seem to more logical to have the Line contain two Point's.


1

For the most part rule Preconditions is validation. With the approach of keeping validation outside of Rule action and execution flow you will get: You will be able to reuse Preconditions. - In most cases it's a useless flexibility. Moreover usually you will have rules only with one precondition and one rule action. There will be a problem of sharing data ...


1

According to Uncle Bob Negatives are just a bit harder to understand than positives. So, when possible, conditionals should be expressed as positives. For example: if (buffer.shouldCompact()) is preferable to if (!buffer.shouldNotCompact()) From Clean Code Chapter 17, Item G29 "Avoid Negative Conditionals" So your first example is the preferable ...


1

I would not make a function for the sole purpose of renaming a ! operator because that's a complete disaster when it comes to interface minimalism and code maintenance with two different conventions, but if you have the choice from the start, make functions the way that's the most obvious to use. To me, that would be using the second form (and only this one),...


1

Is this a real application you're working on? 1000 different paths based on one parameter, all totally unrelated? I suppose if that parameter is "transaction code" it might be barely possible. Even there, 1000 is a lot of different paths. But that said ... As JacquesB notes, a C# switch creates a jump table. This is about as efficient as it is going to get ...


1

It is not possible due to the fundamentals of how the grammar and compiler works. Expressions are evaluated "bottom up", which means the expression MyClass.X evaluates to its int value before this result is fed as an argument the function. Your proposal seem to suggest that the context - the type of the parameter - could direct if the expression should be ...


1

Foo.Do() meaning the invocation and Foo.Do being the,delegate is fine. Foo.X being the property as well as the getter delegate and the setter delegate depending on subtle context differences is confusing. Good features that aren't overwhelming good don't even get into C#, this seems like an actual bad one. If you want short write once code try Perl. There ...


1

Since you want to be able to launch multiple instances of your monitoring application and be able to use the solution even if no one is "listening", eventually all of the data needs to get distilled into some sort of central data store (data base, flat file, in memory in some central application). Personally I would stand up a web service for your logging ...


1

C# and Java are very similar languages syntaticaly. But what you are really comparing here is the ease of programming for the frameworks you have to use to make apps for these platforms. Ie WPF and the android app framework. In my view WPF and the other various microsoft frameworks have a maturity and 'solidness' which exceeds comparible offerings. You ...


1

Database enums are for situations where something is necessarily hard coded. The enum creates a binding between the database data and something that is hard coded into the source code. Don't think of that as meaning that they are never useful, since there are situations where this is acceptable and necessary. Rather, don't use an enum unless you have this ...



Only top voted, non community-wiki answers of a minimum length are eligible