Hot answers tagged

190

I developed ASP .Net WebForms applications for 3 years, and after one day of doing an MVC tutorial I was sold. MVC is almost ALWAYS the better solution. Why? The page lifecylce is simpler and more efficient There is no such thing as controls besides html controls. You don't need to debug your output to see what ASP .Net is generating. ViewModels give you ...


124

In my opinion: yes they are, and yes you should. They give you confidence in the changes you make (everything else is still working). This confidence is what you need to mold the code, otherwise you might be afraid to change things. They make your code better; most simple mistakes are caught early with the unit tests. Catching bugs early and fixing them is ...


95

No. The concept behind unit tests is based on a premise that has been known to be false since before unit testing was ever invented: the idea that tests can prove that your code is correct. Having lots of tests that all pass proves one thing and one thing only: that you have lots of tests which all pass. It does not prove that what the tests are testing ...


60

If you've ever seen the benefit to writing a main method to test some small piece of code for school, unit testing is the professional/enterprise version of that same practice. Also imagine the overhead of building the code, starting your local web server, browsing to the page in question, entering the data or setting the input to the proper test seed, ...


49

Unit testing has something of a mystique about it these days. People treat it as if 100% test coverage is a holy grail, and as if unit testing is the One True Way of developing software. They're missing the point. Unit testing is not the answer. Testing is. Now, whenever this discussion comes up, someone (often even me) will trot out Dijkstra's quote: "...


44

This is a stale question with a lot of answers but none had the answer I would have expected to be listed. The short answer is: Use ASP.NET MVC if you intend to properly build a web application with modern programming conventions and industry embraced patterns for the ASP.NET platform. On the down side you will be expected to know how HTML and client-side ...


41

It Depends This is an answer that you will see a lot of when it comes to software development, but the usefulness of unit tests really depends upon how well they are written. A nominal number of unit tests that check over the functionality of the application for regression testing can be quite useful; however, a plethora of simple tests that check the ...


40

private void Demo() { // Do something, given that the result doesn't matter. } public void Do() { Task.Factory.StartNew(this.Demo); // The following line will be executed without waiting for the result. DoSomethingElse(); } Note that starting a method without caring about the result or about exceptions it can throw is risky. If an ...


39

I am a complete and total convert to ASP.NET MVC and have not looked back, that said I do still have to maintain several very large WebForms apps. Here's my take on it: WebForms Use these when you have some serious heavy lifting to do with grids. The grid controls are really very nice when you have a simple dataset that fits nicely in a tabular format and ...


38

Again, this is only for my plant, and I'm the only one who will ever be supporting it unless I leave the company, and then my replacement would be supporting it. Not someone else already in the company. 1 -- Don't Assume you're the only one who's going to support this. You do like your sick time and vacation, right? What if you need to take extended ...


38

Projects done for university classes differ vastly from business applications you'll write at your work. The difference is lifespan. How long does university project "live"? In most cases, it starts when you write first line of code and ends when you get your mark. You could say that, effectively it only lives for the time of implementation. "Release" is ...


36

Generic repository is even useless (and IMHO also bad) for Entity Framework. It doesn't bring any additional value to what is already provided by IDbSet<T> (which is btw. generic repository). As you have already found the argument that generic repository can be replaced by implementation for other data access technology is pretty weak because it can ...


33

Welcome to one of the hardest problems in non-computational programming - properly representing dates and times to end users. Realistically, timestamps should be stored in a fixed single representation regardless of how they will be interpreted, because no matter how hard you try, you will always have ambiguous cases, and you can't resolve them without a ...


33

You're overestimating the importance of source code, and underestimating the importance of everything else in the value chain of selling software. Sure, a contractor might steal your source code. But what then? Will they be able to create a release, maintain the code further, contact your customers and sell them a knock-off for a lower price? Almost ...


30

This is not a direct answer to the question, more of an expansion on it. When you launch a new app I recommend logging everything the user does: log in, log out, scratches their a**, everything. If it's web-based, consider using heat maps so you know what their mouse was doing. When I was on the BravoX project at Xerox in the late 70's we recorded pixel-by-...


25

is writing unit tests for ASP.NET webforms something that is done often, and if it is: how do i resolve the "dynamic environment" issue ? It is not often done. Working with UI elements isn't what unit tests are good at, since there's no great way to programmatically verify that the right things end up on the screen at the right places. Would you guys ...


25

The answer to this question is completely subjective. The length of time it takes a developer to come up to speed can depend on: the developer's level of knowledge and professional experience the level of complexity of the application(s) or the level of documentation for the same the ability of current application "experts" to onboard new developers. By "...


25

One reason is security - if (haha! when) a hacker gains access to your front-end webserver, he gets access to everything it has access to. If you've placed your middle tier in the web server, then he has access to everything it has - ie your DB, and next thing you know, he's just run "select * from users" on your DB and taken it away from offline password ...


24

Stop! You have a bigger problem than the readability. It looks like you don't understand how object initializers work. Let's create a disposable class which traces its execution: public class Demo : IDisposable { private string hello; public Demo() { Debug.WriteLine("The parameterless constructor was called."); } public Demo(...


24

When you start a project and have a particular need, you have a choice: Either you implement your own solution from scratch, Or you use an existent library or framework. When implementing your own solution, you introduce several risks: The needs may evolve, requiring you to constantly write more and more code. Ultimately, the code you've originally ...


23

In my applications I have always separated things out, with different models for the database (Entity Framework) and MVC. I have separated these out into different projects too: Example.Entities - contains my entities for EF and the DB context for accessing them. Example.Models - contains MVC models. Example.Web - web application. Depends on both Example....


22

.NET Framework is a VM, a JIT compiler, an object memory system consisting of a memory allocator and a garbage collector, a loader, a linker, and a runtime system (collectively called the Common Language Runtime (CLR)) which executes and supports a language called Microsoft Intermediate Language (MSIL). It is also a class library called the Base Class ...


21

At my current job I am the sole developer and when I started nobody had any knowledge of the code. I was given a codebase with 200k lines of code and told to implement new functionality against this codebase from day 1. It probably took a week before I was writing useful code and three months before I understood the codebase well enough to track down most ...


19

The most direct quote I've found is part of Scott Guthrie's announcement of the MVC 4 roadmap, back in 2012, (apparently offline but available via the Wayback Machine) which contains the following quote: Json.NET: We plan to use the community developed Json.NET serialization stack in our default JSON formatter in ASP.NET Web API. Json.NET provides the ...


18

There really isn't enough information, as per Thorbjørn's comments. Caching, when done wrong, can cause you & your users lots of grief. Make sure you need to worry about caching before over-complicating your application. So, in the absence of information that indicates you really need to cache, don't cache. [General rule of optimization: If you need ...


17

It depends. But IMHO, it should take about a month to know your way around, and up to six months to be normally productive. An interesting exercise, if you have time, etc: Take a part of the application, and reprogram it in another language, if you know any. Or, try reading all of the source code that you can, and write down what it does. That should help ...


17

This is like asking what the difference is between an apple and an apple core. These two architectures aren't replacements for one another. I think a more accurate view is that the 3-tier architecture augments MVC. The MVC Architecture Models: These represent "stuff" in your application. This layer has gotten a little fuzzy in recent years, as I will ...


17

Is CQRS a relatively complicated and costly pattern ? Yes. Is it over-engineering ? Absolutely not. In the original article where Martin Fowler talks about CQRS you can see a lot of warnings about not using CQRS where it's not applicable: Like any pattern, CQRS is useful in some places, but not in others. CQRS is a significant mental leap for all ...


16

Yes, the reason it defaults to once a day is out of a worry that the web app could have a memory leak. The biggest downside to frequently recycling IIS app pools is that it will cause web.config reading, assembly loading, and a recompilation of asp.net pages and (if you don't believe in pre-compiling them) code behinds. This is a rather heavy process and it ...


16

ASP.NET Web API is a "non-opinionated" framework to build HTTP Service regardless of REST or RPC. It is Microsoft's best implementation of RFC 2616 (HTTP Spec). Certainly you can build your own API but ASP.NET Web API: Built based on the Russian Doll model which allows for lego-like modules to be added to the HTTP pipeline Makes HTTP first class citizen so ...


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