Search Results

Search found 740 results on 30 pages for 'kyle burns'.

Page 2/30 | < Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • When is my View too smart?

    - by Kyle Burns
    In this posting, I will discuss the motivation behind keeping View code as thin as possible when using patterns such as MVC, MVVM, and MVP.  Once the motivation is identified, I will examine some ways to determine whether a View contains logic that belongs in another part of the application.  While the concepts that I will discuss are applicable to most any pattern which favors a thin View, any concrete examples that I present will center on ASP.NET MVC. Design patterns that include a Model, a View, and other components such as a Controller, ViewModel, or Presenter are not new to application development.  These patterns have, in fact, been around since the early days of building applications with graphical interfaces.  The reason that these patterns emerged is simple – the code running closest to the user tends to be littered with logic and library calls that center around implementation details of showing and manipulating user interface widgets and when this type of code is interspersed with application domain logic it becomes difficult to understand and much more difficult to adequately test.  By removing domain logic from the View, we ensure that the View has a single responsibility of drawing the screen which, in turn, makes our application easier to understand and maintain. I was recently asked to take a look at an ASP.NET MVC View because the developer reviewing it thought that it possibly had too much going on in the view.  I looked at the .CSHTML file and the first thing that occurred to me was that it began with 40 lines of code declaring member variables and performing the necessary calculations to populate these variables, which were later either output directly to the page or used to control some conditional rendering action (such as adding a class name to an HTML element or not rendering another element at all).  This exhibited both of what I consider the primary heuristics (or code smells) indicating that the View is too smart: Member variables – in general, variables in View code are an indication that the Model to which the View is being bound is not sufficient for the needs of the View and that the View has had to augment that Model.  Notable exceptions to this guideline include variables used to hold information specifically related to rendering (such as a dynamically determined CSS class name or the depth within a recursive structure for indentation purposes) and variables which are used to facilitate looping through collections while binding. Arithmetic – as with member variables, the presence of arithmetic operators within View code are an indication that the Model servicing the View is insufficient for its needs.  For example, if the Model represents a line item in a sales order, it might seem perfectly natural to “normalize” the Model by storing the quantity and unit price in the Model and multiply these within the View to show the line total.  While this does seem natural, it introduces a business rule to the View code and makes it impossible to test that the rounding of the result meets the requirement of the business without executing the View.  Within View code, arithmetic should only be used for activities such as incrementing loop counters and calculating element widths. In addition to the two characteristics of a “Smart View” that I’ve discussed already, this View also exhibited another heuristic that commonly indicates to me the need to refactor a View and make it a bit less smart.  That characteristic is the existence of Boolean logic that either does not work directly with properties of the Model or works with too many properties of the Model.  Consider the following code and consider how logic that does not work directly with properties of the Model is just another form of the “member variable” heuristic covered earlier: @if(DateTime.Now.Hour < 12) {     <div>Good Morning!</div> } else {     <div>Greetings</div> } This code performs business logic to determine whether it is morning.  A possible refactoring would be to add an IsMorning property to the Model, but in this particular case there is enough similarity between the branches that the entire branching structure could be collapsed by adding a Greeting property to the Model and using it similarly to the following: <div>@Model.Greeting</div> Now let’s look at some complex logic around multiple Model properties: @if (ModelPageNumber + Model.NumbersToDisplay == Model.PageCount         || (Model.PageCount != Model.CurrentPage             && !Model.DisplayValues.Contains(Model.PageCount))) {     <div>There's more to see!</div> } In this scenario, not only is the View code difficult to read (you shouldn’t have to play “human compiler” to determine the purpose of the code), but it also complex enough to be at risk for logical errors that cannot be detected without executing the View.  Conditional logic that requires more than a single logical operator should be looked at more closely to determine whether the condition should be evaluated elsewhere and exposed as a single property of the Model.  Moving the logic above outside of the View and exposing a new Model property would simplify the View code to: @if(Model.HasMoreToSee) {     <div>There’s more to see!</div> } In this posting I have briefly discussed some of the more prominent heuristics that indicate a need to push code from the View into other pieces of the application.  You should now be able to recognize these symptoms when building or maintaining Views (or the Models that support them) in your applications.

    Read the article

  • Obtaining positional information in the IEnumerable Select extension method

    - by Kyle Burns
    This blog entry is intended to provide a narrow and brief look into a way to use the Select extension method that I had until recently overlooked. Every developer who is using IEnumerable extension methods to work with data has been exposed to the Select extension method, because it is a pretty critical piece of almost every query over a collection of objects.  The method is defined on type IEnumerable and takes as its argument a function that accepts an item from the collection and returns an object which will be an item within the returned collection.  This allows you to perform transformations on the source collection.  A somewhat contrived example would be the following code that transforms a collection of strings into a collection of anonymous objects: 1: var media = new[] {"book", "cd", "tape"}; 2: var transformed = media.Select( item => 3: { 4: Media = item 5: } ); This code transforms the array of strings into a collection of objects which each have a string property called Media. If every developer using the LINQ extension methods already knows this, why am I blogging about it?  I’m blogging about it because the method has another overload that I hadn’t seen before I needed it a few weeks back and I thought I would share a little about it with whoever happens upon my blog.  In the other overload, the function defined in the first overload as: 1: Func<TSource, TResult> is instead defined as: 1: Func<TSource, int, TResult>   The additional parameter is an integer representing the current element’s position in the enumerable sequence.  I used this information in what I thought was a pretty cool way to compare collections and I’ll probably blog about that sometime in the near future, but for now we’ll continue with the contrived example I’ve already started to keep things simple and show how this works.  The following code sample shows how the positional information could be used in an alternating color scenario.  I’m using a foreach loop because IEnumerable doesn’t have a ForEach extension, but many libraries do add the ForEach extension to IEnumerable so you can update the code if you’re using one of these libraries or have created your own. 1: var media = new[] {"book", "cd", "tape"}; 2: foreach (var result in media.Select( 3: (item, index) => 4: new { Item = item, Index = index })) 5: { 6: Console.ForegroundColor = result.Index % 2 == 0 7: ? ConsoleColor.Blue : ConsoleColor.Yellow; 8: Console.WriteLine(result.Item); 9: }

    Read the article

  • How do I start my career on a 3-year-old degree [on hold]

    - by Gabriel Burns
    I received my bachelor's degree in Com S (second major in math) in December 2011. I didn't have the best GPA (I was excellent at programming projects and had a deep understanding of CS concepts, but school is generally not the best format for displaying my strengths), and my only internship was with a now-defunct startup. After graduation I applied for several jobs, had a fair number of interviews, but never got hired. After a while, I got somewhat discouraged, and though I still said I was looking, and occasionally applied for something, my pace slowed down considerably. I remain convinced that software development is the right path for me, and that I could make a real contribution to someones work force, but I'm at a loss as to how I can convince anyone of this. My major problems are as follows. Lack of professional experience-- a problem for every entry-level programmer, I suppose, but everyone seems to want someone with a couple of years under their belt. Rustiness-- I've not really done any programming in about a year, and since school all I've really done is various programming competitions and puzzles. (codechef, hackerrank, etc.) I need a way to sharpen my skills. Long term unemployment-- while I had a basic fast-food job after I graduated, I've been truly unemployed for about a year now. Furthermore, no one has ever hired me as a programmer, and any potential employer is liable to wonder why. Old References-- my references are all college professors and one supervisor from my internship, none of whom I've had any contact with since I graduated. Confidence-- I have no doubt that I could be a good professional programmer, and make just about any employer glad that they hired me, but I'm aware of my red flags as a candidate, and have a hard time heading confidently into an interview. How can I overcome these problems and keep my career from being over before it starts?

    Read the article

  • Where's the source code?

    - by Kyle Burns
    I've been contacted by several people through this blog asking about the missing source code for the "Beginning Windows 8 Application Development - XAML Edition" book (the book is available at http://www.amazon.com/gp/product/1430245662/http://www.amazon.com/gp/product/1430245662/) and wanted to share this with others who may have come to this blog looking for it but may not have communicated with me.  The publisher (Apress) does know that the source code is not posted on the book's product page and will be correcting it.  Apress is located in New York City and things were slowed down a little bit last week due to the storm, but I've been assured they will be correcting the product page as soon as they can.  Thanks to everyone who has bought the book and I especially appreciate your patience.

    Read the article

  • Android ActiveSync/Outlook Error

    - by Kyle B.
    Getting the following error when attempt to press "Refresh" inside the Mail app for an exchange server account. Using an Android 2.1 device (Evo). "Exchange email synchronization is disabled". I can send outbound messages, but new emails are not coming in. Anyone know what would cause this error? Thanks, Kyle

    Read the article

  • Sirius Satellite Radio Streaming via XBOX 360

    - by Kyle B.
    Anyone have any luck with this? I've found a number of articles which point to an application uSirius which is apparently discontinued (bought out by Apple or something it looks like) but it is nowhere I have found. Basically I know media center has some baked in functionality for XM radio streaming, but nothing for Sirius radio. Anyone have any luck with this? Thanks, Kyle

    Read the article

  • Trouble using remote desktop when connected via Cisco VPN

    - by Kyle B.
    I just setup my Cisco VPN and everything appears to be working fine. I opened the 'remote desktop' application and am unable to connect to my work desktop machine. When I disable Windows Firewall, I am able to connect, but not when Firewall is enabled. Is there a specific settings inside Windows 7 Firewall that should I be enabling or disabling for this to work without having to shut down the entire system? I can post this in superuser.com instead if you feel it belongs there, but posted here due to it being related to VPN and Firewall. Thanks, Kyle

    Read the article

  • Windows 7 Standy/Hibernate Freeze/Lockup

    - by Kyle
    I'm running Windows 7 Ultimate on a MSI U100 Netbook which often experiences a lockup or freeze whilst hibernating or shutting down. I have a friend with an Asus netbook running Windows 7 who has experienced the same issue. This happens to me perhaps 1-2 times a week, and is frustrating as hell because it will just sit there running flat out (the fan goes to max after a while) until the battery dies if I don't notice it first. Just wondering if anyone has had any similar issues or might be able to point me in the right direction. The freeze occurs when the screen has faded to black. The HDD light flickers for a few moments then just sticks on solid. I haven't been able to isolate any apps which may be causing this either. It will be fine one standby, and lock up the next with no new apps open. Any thoughts greatly appreciated. Cheers, Kyle

    Read the article

  • Chrome browser caching

    - by Kyle B.
    I do a lot of development on my local machine and would like to start using Chrome, however I cannot seem to do a hard-refresh (ctrl+f5) or any other key combination to get my browser to forcibly refresh all content @ http://localhost. I change projects frequently in IIS and this presents a problem because I see stylesheet and image data from my previous project with no way to get this page to reload without forcibly dumping all cache data from the settings menu. Is there another key combination I am missing, or is there a place I can (on a site by site basis) turn off caching? I prefer not to have to clear out my temporary files in the browser settings as I switch projects frequently. Thanks, Kyle

    Read the article

  • Concatenating Date Values - SQL Injection

    - by Kyle Rozendo
    Hi All, We currently receive parameters of values as VARCHAR's, and then build a date from them. I am wanting to confirm that the method would stop the possibility of SQL injection from this statement: select CONVERT(datetime, '2010' + '-' + '02' + '-' + '21' + ' ' + '15:11:38.990') Another note is that the actual parameters being passed through to the stored proc are length bound at (4, 2, 2, 10, 12) in correspondence to the above. Thanks a ton, Kyle

    Read the article

  • 128-Bit Hash Method

    - by Kyle Rozendo
    Hi All, Does anyone know of a hashing method that you can use with .NET, that will output 128 Bytes? I cannot use SHA-2+ generation hashes, as it's not supported on many client machines. Thanks, Kyle

    Read the article

  • Regex Replace Between Quotations

    - by Kyle Rozendo
    Hi All, I am wondering on where to begin to perform the following replace in regex: Read file (.cs file) Replace anything between quotations ("e.g:") with its uppercase version ("E.G:") By example: string m = "stringishere"; Becomes string m = "STRINGISHERE"; Thanks in advance, Kyle

    Read the article

  • JButton keyboard shortcuts

    - by Kyle
    Hello, I have two JButtons and I would like to allow them to be used by the Arrow keys whenever the JFrame is in focus, Can anyone point me in the right direction about this? Thanks ~ Kyle

    Read the article

  • T/SQL Efficiency and Order of Execution

    - by Kyle Rozendo
    Hi All, In regards to the order of execution of statements in SQL, is there any difference between the following performance wise? SELECT * FROM Persons WHERE UserType = 'Manager' AND LastName IN ('Hansen','Pettersen') And: SELECT * FROM Persons WHERE LastName IN ('Hansen','Pettersen') AND UserType = 'Manager' If there is any difference, is there perhaps a link etc. that you may have where one can learn more about this? Thanks a ton, Kyle

    Read the article

  • .NET Web Service Security

    - by Kyle Rozendo
    Hi All, I am looking for some guidelines that one should stick to with .NET Web Services. What does one need to check for/do when it comes to Web Services? Are there any guidelines specifically for .NET Web Services? Thanks, Kyle

    Read the article

  • Convincing Management to use WCF

    - by Kyle Rozendo
    Hi All, I asked another question, stating that the I am unable to use WCF in a new Web Service project and have come to see that it seems to be the technology to use in regards to extensibility and security. My question is a simple one: How can I persuade management (and developers for that matter) to move over to using WCF as opposed to other web service technologies (ASMX/CFC)? They won't be concerned with a comparison between the types (especially with regard to ASMX), simply what there is to gain. Thanks for your time, Kyle

    Read the article

  • Visual Studio Team Suite

    - by Kyle Rozendo
    Hi All, From a developer perspective, what would myself and my team gain from using Visual Studio Team System and Visual Studio Team Foundation Server? I can see some features and the like, but what have you gained from using the two versus using Visual Studio Professional and SVN. Thanks, Kyle (Apologies if there's a dupe, I can't find it though)

    Read the article

  • Impact of Multiple .ToUpper()'ing

    - by Kyle Rozendo
    Hi All, This is not a question of premature optimization per se. On the garbage collector and memory in general, what would hundreds of ToUpper() operations (many could be duplicated) do to a program, mainly in regard to the immutability of strings? Thanks, Kyle

    Read the article

  • How can I dump my MS SQL Server Database Schema to a human readable & printable format?

    - by Kyle West
    I want to generate something like the following: LineItems Id ItemId OrderId Price Orders Id CustomerId DateCreated Customers Id FirstName LastName Email I don't need all the relationships, the diagram that will never print correctly, the metadata, anything. Just a list of the tables and their columns in a simple text format. Has anyone done this before? Is there a simple solution? Thanks, Kyle

    Read the article

  • Testing Mobile Sites

    - by Kyle Rozendo
    Hi All, We are about to launch a mobile site and are wondering what the best way of testing across as many mobile browsers as possible would be? This could be a company that does this sort of thing, or a way in which to do it in-house, we're not being picky. Thanks, Kyle

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >