Wednesday, October 29, 2014

Creating a custom snippet in Visual Studio 2013

Bleh. Checklist-simple procedure that I'm tired of re-researching.

First, reference material from MSDN

Altering an Existing Snippet

If you want to alter an existing snippet to make it line up better with your workflow:

  1. Ctrl+K, Ctrl+B (or Tools >Code Snippets Manager)
  2. Find the target snippet
  3. Highlight the "Location:" field above and copy to clipboard.
  4. Open >File...
  5. Paste the snippet location
  6. File >Save (filename) as...
  7. Browse to your snippet repo (you do have someplace safe to store these as 'source' documents right? these are productivity enablers after all)
  8. Name it appropriately (Custom usually works well)
  9. Proceed to the next section.

Build Your Own

If you're creating something from (mostly) whole cloth... well, don't reinvent the wheel. Follow the steps above but for the target select an existing snippet that does the same kind of thing you want (scaffolding with fill-in templating like the 'if' snippet, or pure expansion, or whatever). That way you have all the details already written and existing syntax to build from. XML documents can be particular and there's no reason to waste your time learning all the special syntax for code snippets. You've more productive things to do than become a productivity tool expert.

Editing

A few words on editing your custom snippet XML. 
Header is where you'll put metadata like author, description, etc. Make sure these accurately reflect what you're doing, and don't try to blame "Microsoft Corporation" for your hacked-together XML drivel.
Double check sections like and because you don't want your snippet to accidentally import libraries that the final code won't require (the 'testm' snippet for example references some unit test libraries that won't be required if you aren't creating unit test code)
Declarations is where you'll set up user input fields and IDE-ready type references (testm is a good snippet to see how these work)
Indents are quite tricky in my experience. They seem to be literal with the first line beginning at the start or the shortcut text in the editor. You'll probably have to play around with it (see importing below). I can't seem to get it to properly indent based on the indent level the shortcut begins at. However it works properly for the built-in 'if' snippet so clearly it's possible. It must be a personal failing.

Importing

  1. Open the snippet manager again (Ctrl+K, Ctrl+B)
  2. Click Import...
  3. Browse to the XML file and select it.
  4. Pick a folder to drop it in. May I suggest the pre-existing "My Code Snippets" folder?
  5. Hit OK and OK.
  6. Test it. Inevitably it's broken in some way. Identify the problem (google can be your friend but more likely for something this esoteric the MSDN doc above will be more useful).
  7. Make the necessary edits and re-import. When you're asked how to handle the conflict just overwrite.
I thought the last time I did this there was a way to edit the snippet in place but I've forgotten how I did that. Possibly by opening the snippet in something other than VS (it's pure XML so most XML editing programs should handle it just fine) but you might have to re-open VS before the changes take effect. Frankly I'm not going to devote any more time to it right now; I'll update the post if I learn better later.

Tuesday, October 14, 2014

Version dependency sucks

Studying MVC. Working through the book and all is well. Unit tests, Ninject, Moq, &etc &etc. Until it discusses [HiddenInput] in chapter 11. It simply doesn't work. I tried several variations of the attribute with (DisplayValue), without it, set to true, nothing changes. The input still shows up. The scaffolded edit form generates exactly as though the attribute weren't there at all.

So I go back to basics. The projects reference MVC and each other, the model object used by the Razor view is the correct class, all the unit tests are fine. So I start casting around Google. Which just gets me a crapton of tutorials on how to use [HiddenInput] (as though it weren't stark obvious when it's working correctly). At this point I'm tearing my hair out. The closest I can come is a hit on StackOverflow for [HiddenInput] hiding the Display functions in Razor. Not my problem.

At wit's end I use the search function on StackOverflow itself to find "hiddeninput mvc" and ... wait, way down the list here is Q: HiddenInput(DisplayValue = false) Works on one dev machine but not another

This isn't quite my issue but it's more promising than anything else I've looked at. As it happens, the OP had issues with the MVC versions that were being referenced on the two machines. Well. All this is on one machine, sooooo... but there are two different projects involved here and of course projects all have their own references. So I dig MVC up in the reference list and look at properties for it in both projects. Bingo. The domain project references 5.2.2 while the web UI project refernces 5.2.0. Score. Of course, if it's possible to specify a version from within VS I don't know how. I have to open the .csproj files in UltraEdit and find the reference entries for MVC. At least it's XML with a readable schema. Update the web UI with the more current version from the domain project (a simple copy/paste) and we're off!

Except we're not. Ninject spews guts all over my dependency injection because it can't find MVC version 5.2.0. DOH! It all becomse clear now. NuGet-ing Ninject into the web UI project forced MVC to version 5.2.0 however I didn't install Ninject in the domain project so it was left defaulted to the more (most?) current version.

The moral(s) of the story? Version dependency (down to the second point level for crying out loud) sucks. And Google can't always find the most relevant answers.

Monday, October 13, 2014

[Desktop|Mobile] first developement

Caveat lector: I'm probably not qualified to ponder this subject nevermind spew my ponderings across the web. But then again, tats wot teh innernet is for innit?

I prefer desktop first. Not because it's easier (mobile dev is still new and will, all things being equal, improve). Not because I'm an old curmudgeon (though I am). Not because I'm a luddite (I'm not). Not entirely because I think 'mobile' everything is overly hyped (that's a whole 'nother post). The reason I feel this way can be summed in one simple analogy.

I'd rather have a van for my family of 5 than a smartcar with a trailer hitched to the back. A smartcar will get one person, maybe two if they're quite friendly, to work and back. Possibly through a small trip to the grocery store. There can't be any significant cargo space in those things; groceries for my family would take up the entire cabin. The smartcar is essentially equivalent to mobile first development. You get the basics (4 wheels, propulsion, steering, safety equipment) done first and eloquently. Then you start bolting on the extras as they'll fit (stereo, sunroof). Then for the things that won't fit on mobile you build out a desktop version. You bolt on a trailer with some seating to carry passengers (still, no cargo space to speak of if you actually want passengers...). Stop right there. The van will do all that with aplomb and grace... while sucking up gas and spewing out fumes like nobody's business. They both have their faults.

So I have a van to tote my groceries and family around with. The passenger and cargo space is important  to me so I want it done right the first time around. All you people with smartcars are going to understand when you build a family (or you already have a family and multiple vehicles, patience I'm getting to that). In the same way if I care about the functionality of the software (in other words, if I would actually give someone money for it) then I want the broadest functionality built in the most efficient, eloquent fashion. Desktop first. For those pieces of software that I don't really care about mobile first is fine. The key point, just like the analogy, is that I don't need the desktop quality experience or functionality for those packages, and indeed I probably don't want to have all those additional features taking up resources or mental energy. MSPaint works great for the vast majority of the graphics editing tasks I have. On the other hand Notepad is not a sufficient text editor for me (for the vast majority of computer users it is more than sufficient) and so I pay for UltraEdit. Note that although I have MSWord it is not a text editor :P

Now, here's where the analogy breaks down. People that need a van will often have a second vehicle to use when they don't need the full capacity of the van. On the other hand typically you'll only use one software package for any given purpose (for a number of important reasons). If you routinely use Photoshop (or GIMP) then you probably won't bother to open MSPaint. I rarely open Notepad because text formats are associated to UltraEdit in the OS and UE is my instinctive go-to in all other cases. There's the rare moment, equivalent to renting or hailing a cab, when I'll open Notepad from the Run... dialog just to act  as a backup clipboard but those are outlying cases. You'll note that in those cases I'm not paying for the mobile-first software package.

There are, of course, cases where the mobile platform has inherent value that makes up for it's reduced capability, again those are outliers. Yet it seems like most mobile developers bewail the fact that they can't get a user to pay $0.99 for their mobile app while for some reason people still pay for desktop apps (and a lot more than a mere $0.99 in most cases). Is it perhaps because reduced functionality apps are used mostly by people that don't need the functionality enough to pay for it on any platform?

Saturday, October 11, 2014

On privacy

Yeah. I'm listening to Glenn Greenwald on TED in Brazil. I quite thoroughly disagree with him though I suspect it's a different kind of disagreement than he's used to.
I value privacy but I value it not as itself (that is, being private from the rest of the world) but as information. Let's face it. In the 'Information Age,' or whatever the hell they're calling it now, privacy is the gold in Fort Knox. The internet and the computing systems we, as a world of people, have built have effectively leveled the walls and we're desperately trying to patch them while yelling and screaming at the looters to stop.

It won't work. The walls can't be rebuilt (and they shouldn't be) and the looters will never stop because, really, who would? People are making money by the boatload on our information. There isn't a force on Earth that can stop them. Look at any pre-digital major corporation; they're all still making money, pretty much the same as they always have.

I have a different proposition. Let the NSA do all their petty spying. Let Google, Faceplant.... er, book, LinkedIn, et al do their tracking. Let them have our webcam feeds. Let everyone correlate to the big 3 credit bureaus if they like and perform statistical analysis with all our Amazon purchases. I frankly don't give a damn. BUT. Not because I have nothing to hide. But because I have one simple stipulation for all the data whores. It's incredibly simple in word (implementation is another story but we're all of us blue-skying here because it's still very new discussion). Let your data free. Publish it; let the public search it (using the same internal mechanisms you use).  Scary? No.

What people fear isn't that the NSA knows you bought a dildo or whatever. It's that you have nothing on the NSA (other than they're a bunch of lying, spying, sneaky creeps). You're worried that your nosy neighbor can search through your ... search queries? But you could look at theirs too in such a world. Because the real value of information to an individual or entity is inversely dependent on how many other entities know that information. Let's look at this side for a bit longer. If everyone knew what was in the diplomats' emails that the NSA snooped (which everyone does now, sincerest thanks Mr. Snowden) then the value of that information to the NSA is roughly nil. Similarly in the reciprocal world I envision (and reciprocity is the key here) the same memos are worth just about nothing to any government because all their emails are public also. Before anyone mentions the 'chilling effect' allow me to say that the full effects global freedom of information won't be apparent until the second generation. The same way nobody grokked the internet until people grew up with it. Global freedom of information will force everyone to realize and accept that everyone is human, that everyone makes gaffes, has some opinions we disagree with, that everyone gets naked, and nearly everyone has sex sometimes. It's only when there's an imbalance of information that privacy matters.

Any schoolchild can tell you this about secrets.
Value = Information/(how many people know it)

Bringing this monologue back to Mr. Greenwald's talk let me address his very valid point about black and white. There are, indeed, no Good people. There are people that are good, but everyone has 'dirt'. Everyone is, when considered completely, Grey. We are imperfect, flawed, weak, and corrupt in our own individual ways. When everyone is forced to acknowledge that about themselves and everyone else then knowing someones weaknesses ceases to be something of value. Indeed, it becomes a strength because we would no longer need to guess which politician is the most corrupt.

Mr. Greenwald goes on at some length about passwords but I'm afraid he's missed the point there. Passwords are not privacy. Passwords are authentication. No, you may not have my bank password; not because i wouldn't want you to see my purchases (again assuming reciprocity, I will not give you an imbalance of power either) but because I don't want you to make purchases in my name. Ditto email. That whole section of his talk made my head ache and if I'd been in the audience I'm afraid I would have gotten thrown out for screaming at him that he's an idiot.

However he was trying  to make the point that people who claim privacy is dead are hypocrites. He does make that point effectively about Eric Schmidt and Mark Zuckerberg. However I stand by my view. But it is a reciprocal view and cannot be implemented by one individual. To give away my privacy while others refuse to give away theirs (and every entity with the wherewithal is spying on us all and hoarding the data to themselves) is ludicrous. Yes, I make some small measures to maintain my privacy. Not because I don't believe my own rhetoric but because nobody else is willing to reciprocate and freedom doesn't work unilaterally

Meh. I'm tired of properly composing my thoughts, and I've other things I need to do as well. I'm not a journalist either. So I'll just jot down some oneliners during the rest of his talk as I listen to it.

Shame? Judgemental eyes of others? Reference the above about humanity becoming more understanding (even compassionate? O.O ) when everyone can know everything about everyone else.

So there's a correlation between being observed and the actions that one is willing to take. But is the mere observation the cause? If you video yourself (you, observing yourself) do you act differently? I submit that it is the imbalance of being observed while making a choice but not being able to observe the other while the other makes that choice that is the root cause of the behavioral change. But then, I'm not a [psych|soci]ologist.

Panopticon? Holy hell. Can we say imbalance of power and observation? My point still stands.

Oh, yes. The Abrahamic god. Still. Every example he gives posits an imbalance of observation.

I do agree about the destructive lessons in the phrase "only people with something to hide fear surveillance."

Dissidents. Yes, they could be tracked by the government. He follows that immediately with the measure of freedom of a government by how it treats its dissidents. Treatment that, if everyone was watched by everyone else, everyone would know. Catch22.

I will take the 1 or 2 generations of suppressed freedom of choice due to mass observation in order to break through to a more idealized humanity that accepts itself for what it is. Sadly, such informational freedom is unlikely to ever happen for emotional, political, and admittedly practical reasons.

I dislike the ad hominem agains Snowden as well. However the mirror accusation is scathing and probably isn't as universally applicable as it's stated. Of course, it feels as good in my gut as it apparently did to the majority of the audience but one has to vomit those feelings out of the gut and examine them thoroughly or you're going to have a hell of a lot of indigestion when those ideas curdle later.

Closing with a pair of personal definitions:
observation: knowledge of events shared among all entities
surveillance: knowledge of events kept secret by one or a few entities

Tuesday, October 7, 2014

No. You don't understand genetics

Unless you're a geneticist anyway. And even then it seems understanding is a quite limited word.

You're a smart, technically apt, curious person? You don't believe me and want proof? Here's a single statistic.
The wheat genome consists of 17 billion (yes, with a 'b') bases. That is, apparently, 5 times more than the human genome. What, you thought you were more complex than wheat? Not at the genetic level, bub.