Author Archives: Garun Vagidov

Naming and Organizing can be so Satisfying

Naming and Organizing can be so Satisfying

To this day it puzzles me that the most important organizational decision that you can make is so often overlooked. Whenever I bring up the importance of naming and proper organizing of projects and namespaces, I get scuffed at. And who out there really knows what the RIGHT way is? I say I don’t but I have a vague idea of what the right way will be for Lunchage, at least till “new shit comes to light”.

There are two main points that need to be addressed. One is the number of assemblies should be kept to an minimum. Two is proper naming of namespaces and classes.
In my experience improper seperation of projects and namespaces is one of the biggest downfalls of any project. As the number of projects grows, two negative consequences inexplicably happen. One, compilation times shoot up to 2 to 5 minutes per build. Plus the just in time compilation of ASP.NET adds another 2 – 5 minutes. Thus if a developer compiles code 50 times in a day, then you are looking at a 100 to 250 minute time waste. Two, traversal and searching for classes becomes a burden. Sure with the lovely “Ctrl-T” in ReSharper I can quickly go to the class, but find usages becomes a 2 minute wait of checking every project. And if you are just browsing the code to get familiar with the application, well good luck and bring a lot of patience.

Minimize the number of assemblies!
Shrinking the number of assemblies down to one or two is the best thing you can do! There a few WEAK arguments for multiple assemblies, but they all fall short when inquiring more deeply about application of such methods. Don’t tell me about your hypothetical situation where monkeys rule the world.

Don’t use IRepository!
Raise your hand if you understand what Repository really means. Now put them down if you ever have a Repository with any kind of load planning. Repositories do not have load planning! Repository from P of EAA and Repository from DDD have nothing in them about load plans and the depth of objects loaded. By my interpretation the object returned is a fully hydrated object plan that does not need further database query. Using ORM tools such as NHibernate we can remove the full hydration by having lazy loading. But when you start going down that path, remember that it leads to hundreds of database queries just for a single action. I bring up the Repository naming because of its misuse, and:

You must have a Common Language!
Just like we agree on the meaning of English words, we must also agree on the meanings of what we name classes and namespaces. Also if you do have a Repository feel free to use the name, and be ready to accept the consequences of following the pattern whatever it entails. Design patterns are one part of the whole of common language for programming. This common language is programming language agnostic and spans operating systems and ignores syntax. This language is also rooted in good programming practices, SOLID principles, and design patterns.

Starting an application with a proper naming structure and organization will save you time and sanity in the long run. If you don’t have the luxury of starting from scratch, then bring your solution up to date, spend some time organizing and cleaning up, you will not regret it!

1 Comment

Standards! Why and How!

Standards! Why and How!

Standards are important!  Developers read more code than they write. Code style standards define how your code looks, they create polarized debates with shouts and battle axes being brandished. Whatever your process is, come up with standards. In my years of development, I found that if it’s simple to keep the code standard then the standard will be followed, opposite applies double and triple. I cannot say what is the best code formatting, since beauty is in the eye of the beholder. I will say that as long as you are consistent, then you are ok in my book. To avoid a bloodbath, have the architect or manager or lead developer put his foot down and set the standards for everyone. Also remind the developers that “Smokey, this is not ‘Nam. This is bowling. There are rules.” Those rules are set for the organization and may not be changed on a whim of one.

Following and caring about standards is a trait of a mature and detail oriented developer. When thousands and hundreds of thousands of lines of code follow the same standard, it is easier to read through the code and easier to find bugs and inconsistencies. Combine that with architectural patterns, name conventions and proper namespace separation, the code becomes a joy to work with and the job becomes much more interesting and exciting.

That was my rant, here is the how. Get ReSharper (need help selling, check the benefits out). I and everyone I know, LOVES ReSharper. No, we are not sponsored by ReSharper. My instructions are for ReSharper. I’m sure there are open source, read free, alternatives that do the code formatting, and if anyone would like to do a post on that please let me know.

The shortcut for ReSharper clean up is “Ctrl – E – C” for Visual Studio scheme and “Ctrl – Alt – F” for IDEA scheme. For silent clean up, “Ctrl – E – F”.

Starting with Code Style Sharing, ReSharper allows for code sharing per solution or not sharing, under “ReSharper -> Options -> Languages -> Common -> Code Style Sharing”. You can also export and import settings to share with your friends.

One of the overlooked features is the “Type Member Layout”, it is also one of the most useful. A consistent member placement makes code easier to navigate to and browse. At the time of this writing, ReSharper does not support “Type Member Layout” import from the settings file, but here is our type member layout. The xml file is pretty straightforward, so by reading it you will get some idea what each node is responsible for.

Another invaluable tool is StyleCop. The documentation is full and rich, so I won’t waste time explaining how it works. What makes StyleCop better is the ReSharper integration. Since the feedback is instant it is easy to follow the standards and quick to notice inconsistencies. StyleCop/ReSharper integration will also run during code clean up fixing most issues. Note when installing StyleCop, make sure you WANT the “Visual Studio Templates” replacement option. While it is possible to revert, it is a pain to do so.

You can either use the default code cleanup profiles or set up your own. To set one up go to “ReSharper -> Options -> Code Cleanup”.  It is a must with the StyleCop ReSharper extension, since most likely you are not following all the default StyleCop rules. Unfortunately the Code Cleanup options cannot be exported.

Grab the standards for Lunchage, use “Import…” under code style sharing to implement our standards.

There are also formatting options part of Visual Studio “Tools -> Options -> Text Editor -> YOUR LANGUAGE -> Formatting”, that has the basic formatting options. You can run default formatting with “Ctrl – K – D” to clean up the current file. It’s a simple and built in formatter, that can do the job for a more disciplined team.

One last pet peeve of mine is Tabs! Use Tabs. Tab is a standard character with a standard width of 4 spaces, but the excellent people behind Visual Studio actually allow you to set the number of spaces to what ever your heart desires. Leaving my preference of 4 spaces up to me and 4 up to you. To change go to “Tools -> Options -> Text Editor -> All Languages -> Tabs”, I prefer the indenting to be “Smart”, “Tab Size” and “Indent Size” to be 4, and most important “Keep Tabs” selected. The Fix Mixed Tabs extension is also helpful for those of us with OCD.

Our tools should make code style standards easy to enforce and easy to follow. There are no excuses not to have standards or enforce them, and if you don’t care about code style standards, then why care about anything in code at all? Naming, Principles and Code Style standards are part of any well seasoned programmer tool belt.

Leave a comment

Application Planning, Mock-Ups

Application Planning, Mock-Ups

Mock-ups are an important part of any application creation. When creating a mock up you want to stay as simple as possible and get the idea across without an influence on the implementation. There a number of excellent tools available for creating complex UI mockups and some that are really simple.
To start, I as a product owner first want to jot down some ideas. Putting something into the computer feels permanent to me. I like paper so i will start with that.



Those were quick to do and got my ideas on paper and out of my head.
Now to focus on something more easily modifiable and that can be shared with the rest of the team. We use Balsamiq Mockups because it’s feature rich, easy to use and quick to get started with. As with any tool the more you use it the better and faster you get with it. Another awesome reason is Mockups To Go, which has even more mock up goodness for download. I spent about 30 mins on this homepage mock up, after a quick discussion over the hand drawn ones.


Now that we got our general plan for homepage we can get started with design and getting some pages out quickly. We will come back to Balsamiq Mockups in the future for other pages, for now we need to focus on showing progress to our product owners and getting their input. Since our product owners are everyone, feel free to post your ideas in the comments.

Release often, release quickly, and try to minimize the bugs!

Leave a comment

Keyboard Ninja: Creating New Items

Keyboard Ninja: Creating New Items

Continuing with our series of becoming a keyboard ninja.

  1. Intro
  2. Creating New Items
 

Creating New Items!

Lets start with an empty MVC shell. If you don’t have MVC 3.0 installed yet, you probably should, since we will be referencing it a lot.

The age old right click on folder in the solution explorer  “Add-> New Item…” is not for the Keyboard Ninja! Same for the “File ->New -> File”. It takes far too long and way too much clicking and scrolling with the mouse.

Of course some may say, could it be that “Ctrl – N” maybe of service, but I say no! Try it yourself, first we get the select file type screen, of course what we usually use is not the default highlight. After selecting the “Visual C# Class”, we get a clean class called “Class1″. But no file in sight, and the cursor at the top of the file, things are not much better than with a mouse click. (the second time with “Ctrl – N” did save the last file type used)

And then there is “Ctrl – Shift – A”, add new item shortcut. It’s not a bad choice if you don’t have ReSharper and you can control the Visual Studio default templates. You can locate and organize project templates, easily edit, and create item templates. It’s a lot easier if you have ReSharper and use the Live Templates feature.

Now lets try my favorite way,” Ctrl – Shift – Ins”. The ReSharper insert template, awful to remember, but we will remap “Ctrl – N” to the this command later on. First press “Ctrl – W – S”, which will either show or focus on the solution explorer, easy way to remember is “W” -> window, “S” -> solution explorer. Select the folder “Controllers” and “Ctrl – Shift – Ins”. Select the “Class” as the template. You can also hit the underlined letter key to insert the template without having to navigate to it, in this case “l”. I am naming mine as “AccountController”. Extend the “Controller”, which will result in a blue pop up to add a reference with “Alt -Enter”.

“Alt – Enter” will be the most used shortcut in the process of programming. This brings up the smart ReSharper options, which officially stands for “ReShaper_ForceCompleteItem”. The short cut works whenever there is a ReSharper menu icon pops up on the left hand side of the code.

Let’s remap “Ctrl – Alt -Ins” to an easier to remember and use “Ctrl – N”. Open the “Tools -> Options -> Keyboard”, and find out what the command for the ReSharper insert template, go to the “Press shortcut keys:” and the command will show up in the “Shortcut currently used by:” dropdown. There is a dropdown because the same keystroke can do different things in different scopes. “Global” applies to shortcuts at any level, “Text Editor” only in text edit mode. The command is “ReSharper.ReSharper_GenerateFileBesides”, lets find it and reassign “Ctrl – N” to that. Go to “Show commands containing:” and start typing in “GenerateFile” the command will become highlighted. The search box is an auto search and its an insensitive contains, so you don’t have to know the exact command to find it. In the “Shortcuts for selected command:” dropdown you will find all the current shortcuts assigned to the command. We are going to add a new one. Go back to “Press shortcut keys:” and “Ctrl – N”, you may get the double shortcut of “Ctrl – Alt – Ins, Ctrl – N”, press “Ctrl – N” again to reset the dialog. Keep “Global” in the scope dropdown and click “Assign”.


Check if the “Ctrl – N” is the right shortcut, by pressing the shortcut keys in “Press shortcut keys:” and checking the currently used by dropdown. There are two items in my list, one is the global ReSharper generate file and the other “SqlEditorNewQuery”  in the “Transact-SQL Editor” scope. Since that will not interfere with the new command I will not remove the assignment. If you wanted to remove the command, then you would have to search for it, and select the shortcut you would like to remove in the dropdown menu and click “Remove”.

Most of the time I am in the middle of class creation when I run across the need for a new class or interface. For our example lets create “AccountService”, that will implement the “IAccountService” interface. Instead of using our newly created shortcut we will just start typing the new interface in as a constructor dependency for our Controller.

“pu” “Tab” will autofill “public”, “Accou” “Tab” will autofill “AccountController”, “(IAccountService accountService)” “Enter” “{“, the auto fill will put in our closing curly brace. The “IAccountService” will appear red, since we do not have that class, navigate  to the “IAccountService” and you will see the red ReSharper can do something about this box, press “Alt – Enter”.

Select create interface(notice the underlined characters), the interface is created at the bottom of the file. Put cursor on the name of the new interface, a new box will appear, a purple pyramid. “Alt – Enter” and select “Move to another file and match type name”. Now you have  a new file, and can be done quickly and efficiently. The only downside, the new file probably does not belong in the same folder. And so far I have not discovered a way to move the file without drag and drop. Once in the right folder, you will have an option to adjust the namespace by “Alt – Enter” on the namespace.

Next: Refactor Options

 

1 Comment

Becoming a Keyboard Ninja, Visual Studio Edition

Becoming a Keyboard Ninja, Visual Studio Edition

In these upcoming posts we will explore how to become the keyboard ninja(definition 2). And you will feel slightly more superior to the mouse using population.

As software developers, more often than not we’re able to think ahead to a problem’s solution well before we can write the code, the only thing getting in our way is a mouse and keyboard.  Fortunately for the .NET development community, there are wonderful tools out there combined with Visual Studio to make our lives easier.

This series of blogs is going to focus on utilizing keystrokes and keeping our grubby fingers off of our mouse as it only serves to slow us down and annoy co-workers.  Once we’re all finished, you will sworn into the secret society of keyboard ninjas. We will also try to train ourselves to be more effective by taking advantage of advanced ReSharper commands and features.

You want to make sure that you use any command you learn right away. Try to use as many shortcuts as you can. Consciously recognize often used button clicks and find keyboard alternatives. One last thing, make sure your keyboard shortcuts are consistent across applications that you use.

To start here is my set up of the keyboard shortcuts and screen layout.

My screen layout is simple, I do not use toolbars. So every toolbar is turned off. On the right hand side I have my Solution explorer always open. That also acts like a tabbed pane for any other narrow windows that can fit there like the Team Explorer and Properties. On the bottom, always minimized are any wide panes like Error lists.

My keyboard shortcuts are set to “Visual C# 2005″ settings, visible in the Tools -> Options -> Environment-> Keyboard(Keyboard Options).

My ReSharper shortcuts are set to “Visual Studio” scheme, visible under ReSharper -> Options -> Visual Studio Integration.

To use the shortcuts we will introduce you should have your settings match ours. If a shortcut doesn’t work you can check what if anything is mapped to that shortcut key stroke. To check it go to the Keyboard Options and go to the “Press Shortcut Keys”, and check which commands are mapped to the shortcut.

We will be back to that screen plenty of times to assign and reassign shortcuts. I will provide the exact commands where I can, feel free to ask clarifications on any that are not straightforward in the comments.

Next: How to create a new file.

Leave a comment

Welcome to the Refresh

Welcome to the Refresh Buffalo blog.  The goal of this site is to keep on enhancing the web development IQ of Western, NY.  If you haven’t traipsed through the rest of the site by now, you should know simply that we are looking to make our local developers better through constant improvement and research of new development techniques.

The developers of this site deal primarily in .NET technologies but are always looking for new framework stacks to further our programming acumen.  We are going to use this blog as a vehicle to put forth all knowledge we’ve gained from working in the web design industry for the past few years.

In the coming weeks we have planned a variety of blogs on topics ranging from proper javascript concepts utilizing Backbone as a scaffolding tool all the way to optimizing every keystroke using unknown functionality from Resharper.  Aside from basic clean coding tutorials, we’re looking to provide insight into the methods great developers have used before us, such as large scale Refactoring examples and use (and misuse) of DDD.

The main contributors to this site have worked in web design and development exclusively for the last six years, working for clients in the Western, NY area such as M & T Bank, New Era Cap,

 

Leave a comment
Do you need quickly support ?

Some text here...

* required
Send Message