Archive for the ‘Code and Development’ Category
May 15th, 2013
When doing automatic tests one often wants to get to the internal classes.
The possibly simplest way is to use InternalsVisbleTo and write
1
| [assembly:InternalsVisibleTo("MyTestingProject.With.FullName)] |
in the testee’s AssemblyInfo.cs
<shrugging shoulders>Thats all there is to it.</shrugging>
One can decorate InternalsVisibleTo with keys and stuff to harden who gets to the internals but why bother? As long as it is dotnet some reflection can get passed the threshold anyway.
Another way I have used is to make a wrapping class “UT_Customer” or method “UT_Create” that 1) wraps the internal class/method, 2) is public and 3) is clearly marked with something conspicuous like “UT?_”. If a drive by programmer sees a method with a weird name and doesn’t bother to read the xml comments and still uses the method and fails; I consider it his fault, not mine. Not that I would use an undocumented method, no never.
May 14th, 2013
I haven’t the full reason for the problem – exactly which implicit line ending that goes wrong – or whatever else that is broken. But the (almost) fix is – don’t use the minified version. At github you can get either version as (respond.min.js or respond.src.js). Go for the latter, it is the non-minified one.
In my unlatched IE7 I get a somewhat stocastic behaviour. When just browsing it first fails but a reload makes the page load properly.
When I debug both the debugger and IE freezes at a regular javascript row in respond.js. ”document = doc.documentElement”. This is also where I give up.
Other browsers – including Safari/Ipad and built-in/Android seems to work alright with the minified version.
March 7th, 2013
When debugging and watching an object one only sees the name of the type in the debugger.
1
| MyProjectNamespace.Meeting |
The quickest solution is to click the little plus sign or use the keyboard right arrow to show the properties. This is ok to do once or twice but doing this for every comparison is a waste of time at best.
Better then is to use SystemDiagnostics.DebuggerDisplay like so:
1 2 3
| [DebuggerDisplay("ID:{ID}, UID:{UID}, Name:{Name}, Type:{this.GetType()}")]
public class Meeting : BaseClass {
... |
to get
1
| ID:1, UID:234abc, Name:XYZ, Type:MyProjectNamespace.Meeting |
The Tip was to use {this.GetType()} in the argument of DebuggerDisplay.
March 2nd, 2013
Visual studio contains snippets. These are “shortcuts” for writing various code. Try writing for in the editor and text is typed in for you and you get placeholders for faster code writing.
One can write code like this oneself. It is quite easy. Just go to menu->Tools->Code snippets manager and work from there; copy, paste and rewrite to your will. (The location field is the folder of the very snippets.)
Here is an example of mine.
I know that some people swear that #region is the devil’s own child but there are other, let’s call us them for pragmatists for now that say that if it fits it fits. The standard snippet outcome for a region is
1 2 3 4 5
| #region // Name of region.
//code
//code
//code
#endregion |
but I prefer
1 2 3 4 5
| #region // Name of region.
//code
//code
//code
#endregion // Name of region. |
So I just copypasted the existing snippet to this; which you can import through above mentioned menu.<?xml version=”1.0″ encoding=”utf-8″ ?>
<CodeSnippets xmlns=”http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet”>
<CodeSnippet Format=”1.0.0″>
<Header>
<Title>#region</Title>
<Shortcut>region</Shortcut>
<Description>Code snippet for #region</Description>
<Author>Microsoft Corporation</Author>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
<SnippetType>SurroundsWith</SnippetType>
</SnippetTypes>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>name</ID>
<ToolTip>Region name</ToolTip>
<Default>MyRegion</Default>
</Literal>
</Declarations>
<Code Language=”csharp”><![CDATA[#region $name$
$selected$ $end$
#endregion // $name$]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
February 27th, 2013
Short story: http://msdn.microsoft.com/en-us/library/ms182470.aspx
I still miss a shortcut for “Debug the last unit test”. There is “Repeat the last run” but that runs and doesn’t debug. Strange since that is what I during times use the most. I have resorted to marking the test and the alt-s-d-enter.
Also: Resharper interferes with the shortcuts but that is more a facet of life I think.
February 4th, 2013
A simple solution copied from here is
1
| sp_msforeachtable "sp_spaceused '?'" |
an almost as simple is the one below copied from here:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
| SET NOCOUNT ON
CREATE TABLE #TBLSize
(Tblname VARCHAR(80),
TblRows INT,
TblReserved VARCHAR(80),
TblData VARCHAR(80),
TblIndex_Size VARCHAR(80),
TblUnused VARCHAR(80))
DECLARE @DBname VARCHAR(80)
DECLARE @tablename VARCHAR(80)
SELECT @DBname = DB_NAME(DB_ID())
PRINT 'User Table size Report for (Server / Database): ' + @@ServerName + ' / ' + @DBName
PRINT ''
PRINT 'By Size Descending'
DECLARE TblName_cursor CURSOR FOR
SELECT NAME
FROM sysobjects
WHERE xType = 'U'
OPEN TblName_cursor
FETCH NEXT FROM TblName_cursor
INTO @tablename
WHILE @@FETCH_STATUS = 0
BEGIN
INSERT INTO #tblSize(Tblname, TblRows, TblReserved, TblData, TblIndex_Size, TblUnused)
EXEC Sp_SpaceUsed @tablename
-- Get the next author.
FETCH NEXT FROM TblName_cursor
INTO @tablename
END
CLOSE TblName_cursor
DEALLOCATE TblName_cursor
SELECT CAST(Tblname AS VARCHAR(30)) 'Table',
CAST(TblRows AS VARCHAR(14)) 'Row Count',
CAST(LEFT(TblReserved, CHARINDEX(' KB', TblReserved)) AS INT) 'Total Space (KB)',
CAST(TblData AS VARCHAR(14)) 'Data Space',
CAST(TblIndex_Size AS VARCHAR(14)) 'Index Space',
CAST(TblUnused AS VARCHAR(14)) 'Unused Space'
FROM #tblSize
ORDER BY 'Total Space (KB)' DESC
PRINT ''
PRINT 'By Table Name Alphabetical'
SELECT CAST(Tblname AS VARCHAR(30)) 'Table',
CAST(TblRows AS VARCHAR(14)) 'Row Count',
CAST(LEFT(TblReserved, CHARINDEX(' KB', TblReserved)) AS INT) 'Total Space (KB)',
CAST(TblData AS VARCHAR(14)) 'Data Space',
CAST(TblIndex_Size AS VARCHAR(14)) 'Index Space',
CAST(TblUnused AS VARCHAR(14)) 'Unused Space'
FROM #tblSize
ORDER BY 'Table'
DROP TABLE #TblSize |
January 25th, 2013
If you are running your development on HTTP but testing, QA and production on HTTPS you might have stumbled on
Do you want to view only the web page content that was delivered securely?

“Do you want to view only the webpage content that was delivered securely” dialogue.
The culprit might be your site loading stuff through HTTP while the site is run through HTTPS; the browser doesn’t like that.
Solution:
Instead of rewriting everything to HTTPS or create a deploy transformation to have different versions in dev, test and the rest just abandon the protocol.
E.g. use:
1
| <script type="text/javascript" src="//www.otherexamplesite.com/cdn/jquery.js"></script> |
instead of
1
| <script type="text/javascript" src="https://www.otherexamplesite.com/cdn/jquery.js"></script> |
Happy hacking!
January 13th, 2013
TL;DR
- You have to have knowledge of your types, either through tools or through syntax.
- Have different naming conventions for different languages.
- A strongly typed compiled language can have any naming convention but a weekly typed should have the types integrated in the variable names.
LONGER
Should one use Hungarian notation (sName, oCustomer), type suffixing (nameString, customerObject) or leave out the type (name, customer). The Rulez have come full circle and we are now back at keeping it simple so name and customer is what we write in coding standards nowadays. I am a die hard fan of compiled and strongly typed languages and I really don’t care. My compiler, my IDE and my plugin take care of finding misspellings and type mismatches.
But…
In my head I couldn’t get the simplest, and as I see it most modern naming convention (name, customer), to work together with the weekly typed javascript language. Keeping track of types in javascript is a problem and if one doesn’t get any help from the variable names – how does one do?
So I set out on a 5 day experiment.
I wrote some real production code with Aspnet Webforms, Knockout, Underscore, Jquery, Ajax and Web services returning Json.
I chose to name variables and methods in their simplest form.
1
| updateCustomers( customers ) |
which iterates and calls
1
| updateCustomer( customer ) |
and returns a bool if everything worked as expected.
My conclusion is that this is a bad idea.
I spent way too much time debugging and tracing the-object-property-having an-array-of-another-object-type and whether the final property had a plural “s” or not. The example is not contrived; I had a view model object containing an object which contained a list of Customers which contained properties, or a property which was a list.
To add insult to injury – Knockout was involved so I had to trace through method calls which made the debugging even more tedious. (don’t get me wrong – Knockout still does it’s work properly – it is my own objects and their relations and above all naming that trips me)
After this real world experiment I now have a case for having the type in the identifier names.
1
| bUpdateCustomers( aCustomer ) |
which iterates the the parameter and calls
1
| bUpdateCustomer( oCustomer ) |
I am not saying hungarian notation is better than suffixing the type but it makes for shorter names. Which makes for less possibility to mistype.
[ before gong berserk on Hungarian notation - please check into the difference between System and Apps. ]
December 17th, 2012
With VS2010; Blend was shipped as a stand alone product. With VS2012; Blend was bundled. Almost.
The Blend that comes with VS2012 only does Win8 ModernUI apps.
But there is a remedy: download Blend preview from here: http://bit.ly/U3Opxh. Login might be required.
November 28th, 2012
Every so often (but more seldom) I hear that IE doesn’t have a debugger.
“What?” I say. ”I have been using a debugger in IE for many years.”
It is (was?) hard to find though. One way was to install Visual studio. Another to install MSOffice. The third was (is) to follow this forgotten, seldom mentioned but still working link to download. I have recently used it for debugging an unpatched IE7 on WinXP.
Today the debugger is one F12 press away.
<rant>The IE debugger has shortcuts which is a must for debugging. Mousing is doable but not for serious work. (YMMV) Chrome, Opera and Firefox have shortcuts too but they mix with the debugee – try setting the focus on the debugee form and then press a shortcut; nothing happens. By the time you, dear reader, read this the problem might have been solved but for now I am right. <mad-professor-laughter/></rant>