Tuesday, May 16, 2017

Microsoft is Losing Me

Firstly, Microsoft has been good to me.  My semi-mastery of Microsoft tools for web development has spawned nearly a 20 year career.  So I am by far not a Microsoft hater.  Yet some recent things that Microsoft is doing has me scratching my head.

  • ASP.Net Core - The idea of having one framework that will run nearly anywhere is a noble one.  But is this really a problem that your average enterprise development team was asking to be solved?  Most (I'm guessing) that use Microsoft Visual Studio for development are solidly in the Microsoft ecosystem.  The idea of running MVC on non-Microsoft servers appeals to what...one percent of the Microsoft ecosystem users?  Plus if I can use free tools to develop open source MVC say, why would I be paying 1000's per year per developer seat for Visual Studio? So I can tweak JSON config files and run things from the command line out of penis envy for Linux users?  Dude I like GUI's.  Seems I'm one of the few.  Maybe that makes me a weak programmer but I grow tired of coda obscura for config files and other command line crap.  Give me a limited set of options in a GUI window that is well documented so I can pick what I need and move on to solving problems not pulling my hair out with being gifted with additional ones from Microsoft.
  • Along similar lines, what is up with XAML?  I knew Silverlight would fail just like few are picking up XAML.  Again, why the GUI hatred all of a sudden?  Weird.
  • Constantly changing things.  We have been jumping through hoops from Microsoft for years.  First ASP.  Then ASP.Net Webforms.  Then MVC.  Now MVC core with helper tags quasi bringing back webform like functionality  (but without the GUI support...sigh).  As we jump through the hoops we leave a scattering of legacy applications behind us.  The bleeding edge buzz word flinging developers build and move on leaving their head aches to others while they pursue fame and glory.  Us rank and file dudes have all these apps to support.  It is starting to get old.  If you wrote a PHP app 20 years ago it would (with minimal tweaking) work fine now.  LAMP stack is still widely used.  Can we say that for Classic ASP aps? Not really, though some decent sites are still powered by it.  What about .net 1 apps?  1.1, 2.0?  MVC 1?  .ASMX web services? Now core?  What happens when Microsoft jukes in a new direction?  Should we constantly be upgrading our apps to feed the beast?
I really like MVC and Sqlite.  For me it is a sweet spot for development.  But I think I'm going to become a real programmer and start branching out to Ubuntu running Node.js.  I bet I can build and app and not touch it for 10 years and it will run fine on the latest version of Node and Ubuntu just fine (though would be ugly as HTML / JS / CSS evolves, but it would still work!).  

Microsoft, you are losing me.

Tuesday, March 28, 2017

xmldatasource

For those of us still stuck supporting and enhancing web forms apps, sometimes it is useful to use an xmldatasource to as fake data until the underlying structure can be worked out.  Pasting a sample of an xmldatasource here to remind me of it's format in the future.  This is what you need for combo boxes



<asp:XmlDataSource ID="MyDataSet" runat="server" XPath="/items/item">
      <Data>
       <items>
        <item desc="field_one" val="some value" />
        <item desc="field_two" val="escape invalid chars" />
        <item desc="field_three" val="vals can by any type just put them line like a string" />
        <item desc="field_four" val="And so on, and so on, and so on" />
       </items>
      </Data>
    </asp:XmlDataSource>

To databind xmlsources to grids, you want the data to be laid out more like this

<asp:XmlDataSource ID="MyDataSet" runat="server" XPath="/items/item">
      <Data>
       <items>
        <item field_one="some value" field_two="escape invalid chars" field_three="vals can by any type just put them lin like a string" field_four="And so on, and so on, and so on" />
        <item field_one="some other value" field_two="escape invalid chars" field_three="vals can by any type just put them lin like a string" field_four="And so on, and so on, and so on" />
      </items>
      </Data>
    </asp:XmlDataSource>

Monday, February 27, 2017

Using the tinyMCE CDN

As you know there are all sorts of text editors out there.  For my purposes tinyMCE works fine.  It has a CDN so with the inclusion of a little javascript, you have a capable wysiwyg text editor without having to install any bits into your code (as long as the CDN is up...).  Here is how I use it.



<script src="//cdn.tinymce.com/4/tinymce.min.js"></script>
        <script>
            tinymce.init({
                browser_spellcheck: true,
                contextmenu: false,
                selector: 'textarea',
                height: 500,
                theme: 'modern',
                plugins: [
                  'advlist autolink lists link image charmap print preview hr anchor pagebreak',
                  'searchreplace wordcount visualblocks visualchars code fullscreen',
                  'insertdatetime media nonbreaking save table directionality',
                  'emoticons template paste textcolor colorpicker textpattern imagetools'
                ],
                toolbar1: 'insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image',
                toolbar2: 'print preview media | forecolor backcolor emoticons',
                image_advtab: true,
            });
          </script>

This works pretty well as a blog editor.  I have to hand put in some HTML for embedded images and videos, but so far that hasn't been a big issue.  I get the raw HTML from the tinyMCE editor for saving like so-

var ct = tinyMCE.activeEditor.getContent({ format: 'raw' });

Quick and easy.  Happy coding.

Friday, January 20, 2017

An Old Programmers Tale of Caution and Encouragement.


This was originally posted [HERE].  The post is so old I worry it will vanish, and I think it is an important read, not just for gaming, but for any project.  So I re-post it here.  God bless rogerborg.
----------------------------

Why I can't write games anymore - a novella
Postby rogerborg » Wed Jan 16, 2008 1:07 pm

Pull up a chair and I'll tell ye a tale. A tale of back in the olden days, when men were real men, women were real women, and small fluffy compilers from Alpha Delorie were real small fluffy compilers from Alpha Delorie.

Back in the Day - about 1994 or so - I found myself with some free time on my hands. So I 'downloadorzed' (hey, it was a novel concept back then) Allegro and djgpp for my supa-phat new 486DX2-66 DOS/Win3.1 PC and decided that I'd write me a game.

Because I'm a sad Trekkie (please, nobody ever tell my daughter why she's named Miranda) I figured that I'd write a computronic version of Star Fleet Battles, easily the most complex board game ever devised by Man or Nerd God. I mean, that thing ships with Errata, Addenda, and Errata in the Addenda.

Bear in mind that at this point, I really had no idea what I was doing. Sure, I had a degree in Computer Science, but being from the Old Skoolz it hadn't taught anything as tawdry as how to actually, you know... write software. I'd hacked the bejeesus out of Netrek, but only to the extent of pwoning it with a 'borg client.

So I went in with an abundance of overconfidence, and no real knowledge of what I was doing, or how to achieve it.

And in about 8 weeks of finger-bleeding coding, I had a playable 2D game written in pure structastic C and debugged with printfs(), much as the Pilgrims must have done. It had no config to speak of: you created ship descriptions in human readable text files, using a 'unit X is based on unit Y' hierarchy, and likewise with scenarios. When you started it up, it presented a simple list of available scenarios. You selected one, and away it went.

But you know what? That primitive pile of junk implemented a significant subset of Star Fleet Battles. Cloaks, shields, damage control, phasers, photons, disruptors, plasma torps, drones, anti-drones, hellbores, fusion beams, expanding sphere generators, tractors, transporters, boarding parties, shuttles/fighters, tugs, pods, star bases, planets and ground bases, all 'modelled' in Windows 3.1 Paint then rendered in glorious spinny 2d-o-rama, replete with asplosions and Star Trek sound effects ripped from the bleeding belly of the burgeoning intartubes. It had AI that provided a moderate if predictable challenge, it had fleets and fleet commands, and it implemented all of my original requirements and a few more besides.

That was in 1994, when I knew nothing and had tools little better than sticks and rocks. In 2008, when I know vastly more about how to design, write and test software, and have tools that would make the 1994 me mess my pants... I honestly believe that I couldn't write that game again.

Want to know why not?

I know too much, and have too much.

I'd second guess myself on design, and design patterns. I'd agonise for weeks over the exact hierarchy of objects, interfaces and responsibility for implementing features, and then I'd change my mind and start over. I'd spend an age carefully abstracting away the presentation from the data so that I could change engines, then I'd spend another age using that flexibility to dither over whether to use engine X for its bells, or engine Y for its whistles. I'd agonise over whether a networked version should be architected as a multiplayer game with AIs, or a single player game with a coop/competitive mode. I'd type a line of code, then Google for an hour to convince myself that it was optimal.

I'd make posts like this rather than actually knuckling down and just writing code that implements the clear goals that I've set myself, because it's more rewarding to talk about it than to worry that I've picked the wrong way of doing it.

In 1994, I was Aquaman. Sure, all I could do was talk to fish, but dammit, when there was a problem to be solved that smelled even remotely piscine, I talked their little fishy fins off. Now I'm El Dorado. I have loads of powers, and can make up new ones as I go, but that just makes it harder to choose one and go with it. A marauding octopus! Should I read its mind? Shoot it with my eye lasers? Create an illusion of a sexy lady octopus? Should I grab it and teleport it to a sashimi restaurant? What to do... what do... oh, never mind, it's eaten Kairo.

So, as we grind and bump towards the conclusion of this senile shaggy dog story, do I have a point to make? A nugget of wisdom to impart?

I do.

First, don't listen to the 2008 Rogerborg. Now I only know what can't be done. I've forgotten what can be achieved though ignorance and determination.

Second, listen to the 2008 Rogerborg when he says to do as he says, and not as he does. If you have a game that you want to write, then write it. Just knuckle down and write it. Don't worry about how optimal your data encapsulation is, just bung everything into a structure and call functions on it. Write naive code, and don't give a stuff about optimisation or resource management. Get stuff on screen, and make it spin.

When you are happy, then you're done.

And here endeth the lesson.

Thursday, January 12, 2017

Three SQLite Gotchas

If you are using SQLite coming from say a Microsoft SQL Server background, here are a few differences that might throw you.
  1. There is no TOP as in "select top 50 from....".  
    Instead you use LIMIT, and you put it at the end of your query like "Select blah from blah order by blah limit 50".
  2. Paging because of the above is actually made easy.  You can use OFFSET with LIMIT for easy paging like so. "Select blah from blah order by and wheres blah limit 20 offset 50..." if you pass in a paging variable like say @page you can times your offset to get you what page you want, like "offset * @page".   There is even a shorthand for it, but with a gotcha...the offset and limit are swapped.  Like "select .... order by blah limit 40,10" actually means offset 40 limit 10, which is counter intuitive but there for backwards compatibility.
  3. CASE.  Case is kind of a bummer for comparisons in SQLite.  you can set in on your indexes or on your connection strings to ignore case on your where @mystring = 'blah' type queries like so

    - programa collate nocase in your connections string
    - collate nocase on the end of your queries
    - or add collate nocase on your index when creating a column

    But alas, not that simple.  this only works for UTF-8, if you are using UTF-16 you have to use more exotic solutions with collate binary (I'll leave a link).

    Out of the box you can fake insensitivity using the like operator,  select blah where x like @xxx +'%'... though note here you are better off adding that % operator on your sql param then having it in your query string, for some reason the later doesn't work for me but maybe I'm missing something.

    Also instr, the equivalent to charindex in SQL, insn't case insensitive.  Bummer.

Some useful links-