Tag Info

New answers tagged

0

You can follow Github's guide to getting your project on Github. Generically, there are several options, assuming you've installed git and possibly a git-related utility: via commandline via a UI See this Stackoverflow post for more info.


2

Making your property private would hide it from the rest of the application. This is probably not what you want. The first code example specifies a private backing field which never actually gets used. This is probably not what you want either. The { get; set; } you're seeing is the syntax for automatically implemented properties. This is syntactic ...


2

What you are looking at are Properties, not constructors. The way the other person does them: private string example; public String Example { { get; set; } } Make me think that he might have wanted to do something like so: private string example; public String Example { get {return this.example;}; set {this.example = ...


1

There are tradeoffs to consider... If the data will always remain integers, you might consider conversion to integers. But beware of predicting the future. If the data needs to be compared or sorted, or otherwise analyzed by range depending on the numeric value, then you might consider conversion to integers. If the data may need to be flexible with regard ...


4

Store them in the database as the respective data types. Instead of storing "1234" as a string, store the int 1234. This does a couple of things for you. It prevents data consumers from having to do the conversion and possible mistakes (not only will this prevent mistakes, but it'll maximize performance for the data consumers. Convert the data before ...


-1

You definitely should design your application with discrete layers - data access, business logic, UI etc. However, I'm going to go against the trend and advise you not to use Entity Framework for your data access layer. An ORM should be purely a mapper between database and POCO classes. In my eyes, EF breaks the single responsibility principle by trying to ...


1

What I think you want is domain driven design, In simple terms separation of concerns. Read about it and you are good to go. To keep it simple since you say yo new, Just have User Interface layer in its own project, a service / logic layer in its own project. a data access layer in its own project and other layers depending on the project. For the data ...


-2

What makes you think the index value or the required range or the name of the table is a useful detail, for an exception? Exceptions aren't an error handling mechanism; they are a recovery mechanism. The point of exceptions is to bubble up to the level of code that can handle the exception. Wherever that level is, either you have the information needed, ...


-2

I'll throw in my own 2 cents and say why my exceptions are bad (most of them surely are). I'm lazy. When I'm too busy typing up a cool new algorithm I thought of, I don't want to be bogged down by paraphrasing in minute detail the code that I just wrote. I don't want to deal with mind numbing insanity like what variable name to call my exception (who ...


0

An alternative approach, which may or may not be appropriate for your situation, would be to implement a queue and have a worker thread or process which processes items in the queue. There would always be only a single instance of the worker. The worker processes requests in a FIFO order. This way you eliminate race conditions - if two users both sign up ...


1

First off, don't use Panels to group related tasks. Use UserControls. I used panels to group controls on my first WinForms application, and it turned into a horrible monstrosity, worthy of appearing on TDWTF. Just...don't do it. Instead, use UserControls. These are kind of like Windows, but are hosted inside of a container, similar to a Button or ...


0

To give a slightly different answer: The offending code has probably been done to spec: The function receives X and returns Y If X is invalid, throw exception Z Add the pressure to deliver exactly to spec (for fear of being rejected in review/testing) in minimum time and with minimum fuss, then you have your recipe for an entirely compliant and unhelpful ...


3

The other answers are quite good and clearly address the correctness concerns. Let me address your more general question: How much work should I place inside a lock statement? Let's start with the standard advice, that you allude to and delnan alludes to in the final paragraph of the accepted answer: Do as little work as possible while locking a ...


0

While I do agree that exceptions should contain as much information as possible, or at least be less generic. In the table not found case, the table name would be nice. But you know more about what you were trying to do at the place in the code where you received the exception. While you often really can't do much to rectify the situation when something ...


0

Exceptions have a language- and implementation- specific cost. For example, C++ exceptions are required to destroy all the living data between throwing call frame and catching call frame, and that is expensive. Hence, programmers do no wish to use exceptions a lot. In Ocaml, exception throwing is nearly as fast as a C setjmp (its cost does not depend upon ...


1

First off, let me burst a bubble by saying even if the diag message is loaded with information that brings you to the exact code line and sub command in 4 seconds, chances are the users will never write it down or convey it to the support folks and you will be told "Well it said something about a violation... I don't know it looked complicated!" I've been ...


0

I would go with locking and making sure that validating the enrollment is single-threaded. This is similar to any one of another similar scenarios where a potentially large number of users are attempting to secure a scarce resource: registering for class/training, booking a seat on an airplane, buying a movie theater ticket in advance for opening day of a ...


7

I don't have an excess of C# experience, or C++ specifically, but I can tell you this - developer-written exceptions 9 out of 10 times are more useful than any generic exception you will ever find, period. Ideally yes, a generic exception will point you to exactly why the error occurred and you'll be able to fix it with ease - but realistically, in large ...


141

Exceptions do not contain useful details because the concept of exceptions has not matured yet enough within the software engineering discipline, so many programmers do not understand them fully, and therefore they do not treat them properly. Yes, IndexOutOfRangeException should contain the precise index that was out of range, as well as the range that was ...


33

Why is it that many common exceptions from system components do not contain useful details? In my experience, there are a number of reasons that exceptions do not contain useful information. I expect that these sorts of reasons would also apply to system components - but I don't know for sure. Security focused people see exceptions as a source of ...


4

The question is specifically asking why do so many exceptions thrown by "system components" (aka standard library classes) not contain useful details. Unfortunately, most developers do not write the core components in standard libraries, nor are detailed design documents or other design rationale necessarily made public. In other words, we may never know ...


4

In my purview, Object is undefinitive, and belongs in a binary format, not in a human-readable text. I don't see the relationship between these two things; there are plenty of good reasons to choose text versus binary: this is not one of them. How it appears is an implementation detail only. any derived type of Object The biggest challenge, then, ...


1

Since myself and others found the @Euphoric benchmark above illuminating, below is an expanded version that adds interfaces, lambdas, delegates and static. As one example, with .Net 4.5.2 and x86 output the result (in million iterations per seconds) consistently grouped into three buckets: No function 1,388.9 MOps/s Non-virtual ...


1

Entry32::Method2 overrides Entry31::Method2, not Entry3::Method2. Since the override chain is broken between Entry3 and Entry31 (it is a shadow - completely different functions as far as the runtime is concerned) the virtual dispatch doesn't pass there.


4

Naming things is hard. But in my experience, ambiguity like this can almost always be solved by using a slightly more verbose name in the right place. The alternative method names you suggested are indeed ugly; in this example my first choice would be to rename the parameters: public interface Component { int Read(int portID, byte[] outputBuffer); ...


2

You're almost there... Putting the REST between the view and the controller would be the right choice. That means that your view, i.e. a javascript code, will send REST calls to your server, which process those calls in the appropriate controller (then the models and etc.). In addition this controller would be responsible for the response back to the ...


0

Instead of passing hardcoded department name to the constructor of Person class, pass the initialized DeptName variable to Person class. private void btnShowTotalSalary_Click(object sender, EventArgs e) { string DeptName = "Unknown Department"; if (rbtHR.Checked) { lblTotalSalary.Text= ...


2

What you are looking for is the concept of a ViewModel. This is an object that contains only data that the view is interested in, and is very often not a 1 to 1 mapping with a business or domain model. It may be a cut down version of a business model, it may be an amalgamation of multiple different business models. If your view needs a count, this can ...


0

I utilized the Producer Consumer design pattern for this implementation. So far the performance has been ideal. I am adding answer as StackCareer won't let me link to this post as a answer but my question was more of a confirmation. I am assuming this will get flagged :/


-1

First, C++ templates can take way more than int and type (example, commentary on turing completeness). Second, generics and templates are two very different solutions to a similar problem. So generics aren't "templates but only for types". C++ templates literally take the input to the template and generate code - replacing the template parameter with the ...


0

I pretty much agree with what @radarbob answer states. For some time I wondered as well, about how one would implement such a design pattern in "real life". It's fine when reading about it to understand the design pattern theoretically, but actually applying it is different. If you have access to Pluralsight I would highly recommend the following video ...


1

In most examples online however, this is exactly what's done Not sure how; neither WebRequest nor its concrete descendant HttpWebRequest do in fact implement IDisposable, so this using (System.Net.WebRequest wr = new System.Net.HttpWebRequest()) { //What? } does not compile. In fact what I find when I google around this topic is mostly ...


3

My question is then, how do I know specifically which classes need to be disposed? Does it implement IDisposable? Yes? Then it needs to be disposed. If not, not. You can maybe get away without it in some apps (C# and modern operating systems in general are better about cleaning up after you), but it is still wrong®. There are a very few framework ...


2

I would start with eliminating the duplicated code first by building a generic creation service, something along the lines of class GenericCreatorService<T> { UnitOfWorkFactory _unitOfWorkFactory; // ... public T Create(Func<T,UnitOfWork> func) { using (var unitOfWork = ...


1

Inject the three Creator-classes and test the calls to them by unittesting the QuickOrderService. This keeps the tests on the relevant classes. Also, you might not need to haul the unitOfWork around. The implementation of Create could be changed to simply create a new transaction if none exists and otherwise return the existing transaction. This could keep ...


4

If you do not apply DI as long as you do not really need it (not even for unit testing), nothing bad will happen. The code does not become error prone, "overly complicated", or hard to maintain. And if you decide to refactor the dependency out later, it will most probably not be much more effort than doing it now. That's a case where the YAGNI principle ...


8

There's a development principle along the lines of DRY and SOLID called YAGNI that is designed to help streamline your development efforts in getting things done and not getting paralysed with indecision over what to do. If you later find that you need to enhance your class, then you will. YAGNI says not to worry so much over it now 'cos you probably won't ...


0

The answer like most things is "it depends". If you want to unit-test the functionality in doSomethingImportantUsingDependency, then you will need to be able to inject the dependency. However, if all that doSomethingImportantUsingDependency does is some property mapping from the result of your database call, then it would be pragmatic to not bother. If ...


10

In C# it is trivial to provide optional dependency injection without coupling yourself to your dependency too tightly: public class SomeOtherClass { private readonly ISomeClass _someClass; public SomeOtherClass(ISomeClass dependency = null) { _someClass = dependency ?? new SomeClass(); } } (or you can make the constructors explicit if ...


2

The general case here is identifying the external interface. It should be possible to write an interface for two systems or modules to interact, define what the method signatures are, data formats, preconditions/postconditions, etc. with zero implementation behind it. Next, separate teams work on separate code that use that interface. Perhaps one team ...


0

Why not do DI instead of newing up the object right in that class? That way you don't have to bother about the original problem because it will be initialized for you and then be passed in. Also it would make it much easier to test your view model. But to answer your original question. In case you have to initialize inside of your class then I would say: ...


32

This is not a question of performance. It is first and foremost a question of correctness. If you have two lock statements, you can not guarantee atomicity for operations that are spread between them, or partially outside the lock statement. Tailored for the old version of your code, this means: Between the end of the while (_runningWorkers >= ...


11

IMHO you are asking the wrong question - you should not care so much about efficiency trade-offs, but more about correctness. The first variant makes sure _runningWorkers is only accessed during a lock, but it misses the case where _runningWorkers might be changed by another thread in the gap between the first lock and the second. Honestly, the code looks ...


4

The entities will also be persisted, read and updated by an ORM, and will serve as models in the MVVM pattern. Why? I mean, you basically came out and said that you'd like your entity (as used by the business logic and used by the ORM) to be immutable, but that you'd like your model (as used by the UI) to be mutable (at least for the add/edit screen). ...


3

I would recommend mapping your DTOs to a domain object and make that domain object immutable Just give it private setters and create it through a factory, instead of passing around the DTO all over. Making it immutable is definitely not a bad idea if you think it should be immutable, documenting still has a risk that a new developer will enter the arena ...


4

There are two straightforward ways to accomplish this. The simplest is to move your common code to a library then make your enemy a library that your game loads. Your enemies can be Dlls. If you want to distribute source, and compile enemies at run time, see ...


0

To improve performance and simulate multiple nodes with regardless of its XML size, you can use XSLT with XML and then use xpath to retrieve nodes. This would be much better.


2

In the first case, you'll have to either create a lookup or to loop through the tags to find a specific tag. In the second case, .NET Framework does that for you when processing the XML file. For instance, if you want to find multiple times (and by multiple, I mean a lot) whether a requirement has a specific tag, the second case usage will be ...


4

However, if you only intend to use COM does this sort of design bring any benefits that I don't see? This snippet of your question is the most important part of your design decision here, and the answer is (as always) it depends. If you only intend to use the library via COM Interop, then you should design the entire system with this in mind. There is ...


3

Well, to be fair, the original author of that article did not use the word "beauty" anywhere in his article, that was you, which might give a biased impression on that for those who did not take the time to read the article by themselves. As far as I have understood that article, the .NET library already existed and was written without COM in mind - ...



Top 50 recent answers are included