Blogroll

Search

H20 – hashtable from scriptblock to powershell Objects

April 21st, 2011 by Karl

Here is another function in my endless Quest at producing Helper functions that simplify doing complicated stuff in PowerShell and that keeps it in the pipeline.

function h20([scriptblock]$sb, [switch]$dontkeepreference = $false)
{
 begin {}
 process{ if ($sb -ne $null)
                {
                  $local:obj = $_;
                  $local:ht = &$sb;
                  if ($local:ht -is [hashtable])
                    {
                        if (!$dontkeepreference) { $local:ht.".." = $local:obj; }
                        New-Object PSObject -Property $local:ht
                    }
                 }
                  if ($local:ht -is [object[]])
                    {
                    $local:ht | where { $_ -is [hashtable]} | % {
                            if (!$dontkeepreference) {$_.".." = $local:obj}
                            New-Object PSObject -Property $_ }
                    }
                }

 end{}
}

Now this function processes the scriptblock for each item coming through the pipeline giving you the opportunity to create one or more Hashtables, and it will take whatever Hashtables you create and create nice PSCustomObjects and pop them out the other side of the pipeline.

Here are some examples

1..10 | h20 { @{karl = $_;dude = $_+1} }

modify the incoming data with an expression

gps | h20 { @{name = $_.processname; mem = $_.workingset / 1MB} }

easily flatten data with subexpressions

get-command -verb get | h20 { @{ name = $_.name;  type = $_.commandtype; synopsis = ($_ | get-help).synopsis ;   } }

don’t lose the incoming pipeline data when you don’t explicitly include it in the hashtable. Its automatically stored in the property “..”
below, while the expression just includes string properties from the get-help object, the actual commandinfo object is stored in “..”

 $a = get-command -verb ("get","set") | h20 { $_ | get-help | % { @{name = $_.name ; synopsis = $_.synopsis} } }
 a[0].".."

Posted in Powershell | No Comments »

Attaching Custom MetaData to Functions

February 1st, 2011 by Karl

One nice thing about object in dotnet, including ETS PowerShell objects is the ability to really store MetaData with a variety of techniques, then later you can walk up to an object programatically, and ask it about itself.

However there really isn’t a way to do this out of the box when it comes to Functions (other than finding out the intrinsic attributes of functions.

One common way is with DotnetAttributes. Most know that there were Certian Dotnet Attributes added to PowerShell V2, such as [Parameter()] and [CmdletBinding()]

A little known secret is that you can actually use ANY dotnet attribute. And as they aren’t really attached to objects like Attributes are on a real dotnet objects so they are totally benign, you just have to work out where to attach it and which attributes to use.

You can attach them to the Function’s ScriptBlock, or its parameters. I find for general MetaData storage the scriptblock is the best place to put it.

Next what attribute. Well you could make your own in C# and use add-type, or you could just pilfer some that are part of the dotnet framework that have agreeable names. Remember they are benign in this context so it really doesn’t matter.

function demo-attributes
{

[System.Configuration.SettingsDescription({
    @{something = 1;
      this = 'that';
      array = (1,2,3);
      sub = @{ sub1 = 1 ; sub2 =2 }
    }})]

[CmdletBinding(DefaultParameterSetName="noname")]
param (
 [Parameter(Position=1,mandatory = $true)]
  [string]$something 

)
1..10
}

So you’ll notice i choose a simple advanced function that already has some dotnetattributes on it, You don’t have to, it could be a simple function, or even an unnamed scriptblock.

in this case used the dotnet Attribute System.Configuration.SettingsDescription and passed in a scriptblock that returned a hashtable containing a complex object.

So this is all good, but the purpose of MetaData is to be able to read it later. My strategy involves

  • Find the attribute on the function’s scriptblock
  • Grab the string from it
  • Put it in a Powershell Data Language DATA section to ensure its content can only be benign
  • Evaluate it to get the complex objects back
$settingstext = ((dir function:\demo-attributes).scriptblock.attributes |Where-Object { $_.typeid -like '*settingsdescription*'  }).description
$settingsscriptblock = $ExecutionContext.InvokeCommand.NewScriptBlock("DATA {" + $settingstext + "}")
&$settingsscriptblock

Posted in Powershell | No Comments »

Run In Module

December 10th, 2010 by Karl

Have you even been working on a a module, call a function, but then get frustrated because you can’t get to that $script:something.

Well modules and scopes is an interesting problem. and when you something from the command prompt of a function OUTSIDE of the module, you can’t see things. This can make working and debugging on things (outside of breakpoints etc) difficult.

Well thankfully there is an undocumented feature on the & call operator

so instead of

& { … }

you can pass in a reference to a module and run a scriptblock

& (get-module somemodule) { … }

and the scriptblock will be run in the modules context..

Well that can be tedious so i’ve made a function called invoke-scriptblockinmodule , with the alias RIM
that allows you to do

rim somemodule { … }

and after you have specified the modulename once, it remembers it so you can just do

rim { … }

Enjoy,


function invoke-scriptblockinmodule
{
[CmdletBinding(DefaultParameterSetName="noname")]
param (
  [Parameter(ParameterSetName='noname', Position=1, mandatory = $true)]
  [Parameter(ParameterSetName='hasname', Position=2,mandatory = $true)]
  [scriptblock]$scriptblock ,

 [Parameter(ParameterSetName='hasname', Position=1)]
  [string] $modulename = $null

)
#TODO: do get-module first and make sure its valid before invoking with &

if (!$global:prossertools) { $global:prossertools = @{} }
 if ($modulename) {
                    $global:prossertools.invokescriptblockinmodulecachedname = $modulename;
                    $module = get-Module ($global:prossertools.invokescriptblockinmodulecachedname)
                    & $module $scriptblock;
                   }
    else {
         if (!$global:prossertools.invokescriptblockinmodulecachedname ) {
            write-host "no name provided or currently cached"
            }
         else {
         $module = get-Module ($global:prossertools.invokescriptblockinmodulecachedname)
            & $module $scriptblock;
        }
    }

}
set-Alias rim invoke-scriptblockinmodule

Posted in Powershell | No Comments »

Where-in and Where-Property-in

November 15th, 2010 by Karl

I’m back again in my quest for general purpose functions slicing and dicing objects and keeping it all in the pipeline.

So in PowerShell you often use the pattern in the pipeline of get-something | where { $_.property -eq $null }

However often you need something more complex. In one case you want to do something similar to to a SQL in.. like select * from mytable where mycolumn in (1,2,3) or such.

in powershell you can do this relatively easily with -CONTAINS but the semantics can be confusing as it seems backwards to us. Here is an example

get-process | where { ("svchost","outlook","powershell" ) -contains $_.processname }

but what if you want to express this differently, and you also want to be able to apply expressions

where-in and where-propertyin are filters that allow to pass through pipeline object that are in a specified array/collection, or that have a property that is in an array or collection. They also can take a scriptblock that can be used to implement a comparision when the relationship isn’t exact. in that scriptblock the variable $__ is created to represent the item in the collection being compared with the pipeline $_ object.

here are some examples

$a = (1..10) , (1..10) | % { $_ } #create some sample data
$a | Where-in (3,4,8)

and with properties

gps | where-propertyin ("powershell","svchost") processname

in hindsight the following would syntax would be a little more intuitive (but its not implemented in this function but could be )

gps | where-property processname -in ("powershell","svchost")

and if you want to graduate to actual expressions with scriptblocks, in adition to the usual PIPELINE object $_ , i added $__ which is the object from the IN list to compare with. Here are some examples.

gps | where-in  ("power","s")  { $_.processname.startswith($__) }

and with properties

gps | where-propertyin ("power","s") processname { $_.startswith($__) }

I also like to use ?. for the alias for this..

and now for the functions themselves

function where-in {
[cmdletbinding()]
param (
[parameter(mandatory = $true,position = 1)]
[system.Collections.IEnumerable]$collection,
[parameter(position = 2)]
[scriptblock]$predicate ,
[parameter(valuefrompipeline = $true)]
$pipelineobject
)
    process {
        if ($predicate) {
            foreach ($__ in $collection) {
                if(&$predicate) {
                    write-Output $pipelineobject
                    break;
                }
            }
        }
        else {
            if ($collection -contains $pipelineobject) {
            write-Output $pipelineobject }
        }
    }
}
set-alias ?in where-in

function where-propertyin {
[cmdletbinding()]
param (
[parameter(mandatory = $true,position = 1)]
[system.Collections.IEnumerable]$collection,
[parameter(mandatory = $true,position = 2)]
[string] $propertyname,
[parameter(position = 3)]
[scriptblock]$predicate ,
[parameter(valuefrompipeline = $true)]
$pipelineobject
)
    process {
        if ($predicate) {
            foreach ($__ in $collection) {
                $_ = $pipelineobject.$propertyname
                if(&$predicate) {
                    write-Output $pipelineobject
                    break;
                }
            }
        }
        else {
            if ($collection -contains $pipelineobject.$propertyname) {
            write-Output $pipelineobject }
        }
    }
}
set-alias ?.in where-propertyin

Posted in Powershell | No Comments »

Silverlight IDE possiblities for DekiScript, Javascript, PowerShell, Ironpython, Ironruby and above.

July 8th, 2010 by Karl

I’m a huge fan on Mindtouch, it’s awesome RESTful Web Orientated Architecture with Dream that makes REST a pleasure but also in a powerful and performant manner with a great async coroutine architecture, and their main product has a build in language Called Dekiscript and i wanted to through together a proof of concept editor for it and that is what is below, but read also afterwards about the possibilities beyond a niche language for one product albiet a great product.

Here is a Link to where i have the interactive demo

Here is a screenshot

and

Here is a Link to where i have the interactive demo
PowerShell

A PowerShell web front end that can talk to the backend using ShellTools PowerShell Job Server , or PoshBoard or PowerGui Pro. With intellisense data coming from your servers, as well as abilities to use Siverlight isolated storage for script repositories/snippets or get hook up to a web based service for that whether it be Evernote, google docs or such?

HTML
Imagine it as an altnerative editor for the SOURCE version, whether for your CMS, with CKeditor, WordPress or such? a nice editor, with rich features, and code completion?

Javascript
A javascript editor that runs real in the browser. where code completion is running against the real life objects you are working with. the ability to quickly run and prototype javascript right there and then, or maybe even include it as an optional interface inside a firefox plugin or firebug or such?

IronRuby , IronPython, Script for .Net , Jint and other DLR languages
With various techniques and gestalt bring other languages into the browser and actually enjoy the code sculpting process right there in the browser without a second class citizen experience typical of web editors. Also with IronRuby and the like you could have macros and all running right there and then and with

Here is a Link to where i have the interactive demo

Posted in Powershell | 3 Comments »

PowerShell running in Dotnet 4

June 26th, 2010 by Karl

Back in the Dotnet 4, VS.NET 2010 Beta days i threw together a PowerShell console host compiled against dotnet 4 but really didn’t do anything with it. It seems that there is a bit of demand for it. So here it is. You can download it and start using it.

It at least allows you to interact with dotnet 4 code in-process. Its not going to turn PowerShell into a dotnet 4.0 citizen as really PowerShell is in what I call “Dotnet 1.9″ style. Its going to be very awkward to interact with Dotnet 4 dynamic objects without some nice helpers but at least it IS possible.

Also I very much doubt that this will be able to be used as a remoting server. However you could have a dotnet 2, PS V2 runspace call this to do some processing. Tedious but at least possible.
Background jobs also aren’t going to run in Dotnet 4, though they possibly may if you manage to rename the original powershell.exe and put this one in its place. I know on windows 7 the ability to do is locked down, but it might be possible on other OSes.

All Command line options should work other than Console files.

Download NOW!!!

Notice the CLR version above?

Download NOW!!!

Just download it, and if with IE make sure you “unblock” the zip, then unzip it and run it anywhere you have PowerShell V2 installed. Enjoy.

Thanks to @jstangroome on twitter to helping motivate me get this out.

Karl Prosser / ShellTools LLC.

Posted in Powershell | 2 Comments »

Portable PowerShell with Portable PowerShell ISE.

June 16th, 2010 by Karl

After a long fight we finally conquered making PowerShell ISE portable also.

Portable ISE

A new Beta of Portable PowerShell should be out by the end of the week that has ISE support and to celebrate we will open up the Beta group to another 100 users.

Go to http://groups.google.com/group/portable-powershell-beta to sign up to the google group. However be aware that the introduction words contain old info , and some bug in google groups is preventing me from updating it, however we’ll send out emails with the relevant information in it.

Posted in Portable PowerShell, Powershell, Shell Tools | 1 Comment »

DSLs / DSVs in PowerShell – Presentation at LangNet 2009

May 14th, 2010 by Karl

At LangNet 2009 last year i presented on DSLs in PowerShell. I wrote up a couple example ones . One which the presentation is in a kind of mini PowerPoint and another where i automated the awesome MindManager mind mapping product with COM to dynamically produce Mind Maps with a PowerShell DSV. Also I presented fellow MVP Jaykul’s awesome and extensive PowerBoots DSL that is one of the best and pithy ways to produce powerful interactive UIs in a scripting language ever.

Here is a link to the Silverlight version of the Video, and to the WMV (95MB) version. The Video is about 12 minutes and audio doesn’t kick in for 30 seconds.

Would anybody like me to post the code to the examples i presented?

-Karl

Posted in Powershell | No Comments »

Passing true dotnet nulls for strings to APIs from powershell

May 7th, 2010 by Karl

There is an issue that can basically prevent you from calling certain dotnet apis.

Basically the trick is just to make a class that’s .tostring() returns a null, and then when you pass that to an api through powershell that takes a string powershell will convert the class to a string() thus calling your code that returns a null..

namespace testnullD
{
public class nulltest
{
public nulltest(){}
public override string ToString() {return null;}
}
}

Here is a complete example you can use.

$a = @"

using System;
namespace ClassLibrary1
{
#proof of concept
public static class Class1
{
public static string Foo(string value)
{
if (value == null)
    return "Special processing of null.";
else
    return "'" + value + "' has been processed.";
}
}
}
"@

$b = @"
using System;
namespace testnullD
{
public class nulltest
{
public nulltest(){}
public override string ToString() {return null;}
}
}
"@
add-type $a
add-type $b
$psnull = new-object testnullD.nulltest
add-type $a
[ClassLibrary1.Class1]::Foo($null)
[ClassLibrary1.Class1]::Foo($psnull)

Posted in Gotchas Etc, Powershell | 1 Comment »

Reflections on iPhoneOS Terms of Service 3.3.1 and Steve Job’s open letter to Adobe. (First Draft)

May 6th, 2010 by Karl

Warning this will be a long post.

I normally don’t get heated about things but the fiasco with the new iPhone developer terms of service has kept my attention for the last few weeks and I suppose it’s because I have skin in the game and like many have developed applications in other languages for the iPhone that until a few weeks ago were perfectly acceptable but now are barred with a few key presses of a lawyers keyboard.

As a caution I haven’t ventured into my iPhone developer portal to view the new terms of service since this fiasco began but here is the excellently crafted offensive clause as reported by the mainstream media.
**************************************************************
3.3.1 — Applications may only use Documented APIs in the manner prescribed by Apple and must not use or call any private APIs. Applications must be originally written in Objective-C, C, C++, or JavaScript as executed by the iPhone OS WebKit engine, and only code written in C, C++, and Objective-C may compile and directly link against the Documented APIs (e.g., Applications that link to Documented APIs through an intermediary translation or compatibility layer or tool are prohibited).
**************************************************************

Breaking Down 3.3.1

The above clause is very carefully worded. It bans a lot, more than just adobe flash. A large number of iPhone games are made in C# using a game engine called Unity 3d. There is a C# to native iPhone compiler called MonoTouch.(MonoTouch is where this affects me directly.)  I believe there are some ruby to native compilers and Pascal as well. The “originally written in” part is a killer because though these languages compile directly to native machine code, they could just as easily compile down to Objective-C . This also effectively bans any kind of metaprogramming techniques or code generation tools. (In fact I recently wanted to store data in source code and I used PowerShell on windows to generate the objective-C to include into my application, which could technically invalidate my objective-C app).

Also “the JavaScript as executed by the iPhone OS WebKit engine”clause  could imply that novel uses  of JavaScript outside of the browser, such as with PhoneGap or Appcelerator Titanium which uses JavaScript not so much to control HTML but to bridge native COCOATOUCH GUI interfaces is banned also.

And the final clause prohibiting any “intermediary translation or compatibility layer” between the application code and the iPhone APIs , in its strictest sense would prohibit your own classes which wrap up some functionality for reuse, to any third party or open source library that makes reuse and certain functionality easier or more consistent (in the “real” or rather wider programming world this is VERY common”) and game engines (including C, C++) almost certainly always have a LARGE abstraction layer between the game code and the underlying platform.

I could go into detail now and rant about those clauses in depth right now, but I will resist and rather dig into Steve Job’s open letter ranting about Adobe and flash and try to break down the fallacies he portrays and deal with things as they really are. First of all I am not a flash fan boy. As a democoder who wrote optimized 3d assembly code and whose friends tried to succeed with “better” animation browser plugins but couldn’t compete with Flash’s pervasiveness I despised flash, yet I respect that its animation capabilities (putting video aside for now) are sufficient and better than the emerging HTML5 and it has a history and is established and successful for reasons good and bad.

Before we go into the “Flash on Mobile” or not argument lets separate two things which Steve Jobs has grouped together -Flash as a Browser Plugin versus the Flash “Packager” for Iphone.

Flash as we know it in a browser runs in a browser and has one set of content (SWF files) that runs the same on every platform. It can’t interact with the computer outside of its browser context, and it runs any programmatic behavior in interpreted action script (with interpreted code being SIGNIFICANTLY slower than compiled code (such as Objective-C or C++). Many of Steve’s argument against Flash and its performance and CPU usage here in the context of a mobile device are valid, albeit misdirected.

From what I understand mobile safari doesn’t even have a browser plugin model, and I DON’T THINK APPLE SHOULD HAVE TO MAKE ONE AND PROVIDE A WAY FOR FLASH TO WORK IN MOBILE SAFARI. However I don’t believe that apple should even be able to ban flash. If Adobe was to work with Opera’s Iphone Browser then that should be fair game. Maybe flash will run slow on it, and the experience wouldn’t be as good for video as H.264 on safari but it would be an option. The market should be able to choose. Also Adobe should even be able to take the open source Webkit engine and make their own browser plugin model and bring their own browser to the iPhone if they wish. Sure the browser may be slower and resemble more the browser experience on android but that should be their prerogative.

Anyhow the Packager for Iphone  in Adobe Creative Suite 5 is a totally different beast, and should be treated differently and most of Steve’s arguments don’t even apply to it technically. The packager for IPhone is more like a 3d game engine. It talks directly to the iPhone APIs (most likely the OpenGLES graphics libraries) for its UI and builds a UI on top of that will code most likely written in C++ that is as finely tuned and engineered for graphical performance as any game engine. Also unlike many existing iPhone games that have somehow managed to shirk an existing apple prohibition on interpreted languages (3.3.2) and use languages like LUA for their game logic , the flash packager, like MonoTouch, compiles its language into native assembly code that statically binds with the iphone libraries, the same as Objective-C does. This last part is very important and really nullifies any justification apple could legitimately have against the flash packager or tools like MonoTouch.

However even 3.3.2  is draconian and the market should be able to decide, and good developers can make applications in interpreted languages run well, and they should have the flexibility to be allowed to. Also in the case of games, game engines are finely tuned and well-engineered, so even if the game logic is written in a slow interpreted language 95+% of execution time isn’t spent there but rather inside the C++/assembler game engine and the 3D graphics drivers from the vendor. If game developers who focus on performance like a religion are able to with good engineering creatively use interpreted languages to be more productive in writing game logic then that innovation and productive toolset should be allowed, as should even the flash packager and other frameworks.

Addressing Steve Job’s open Letter

So let’s breakdown Steve’s misinformation in his Thoughts of Flash letter.

Open Vs Closed

First he brings up the Open versus Closed. Yes flash is proprietary but it’s much more open that the IphoneOS. Adobe doesn’t police who makes what to run on flash. Developers can make any type of flash animation, application of video that they please, and they don’t even have to use Adobe tools to do so. Its open enough, unlike IphoneOS , that third party tools such as Swish can produce Flash content, and even many metaprogramming tools can generate Flash content on the fly. The only closed aspect of Flash is the player, just as say Internet Explorer is closed, yet though I’m uncertain, a third party could likely implement a SWF flash player if they choose to invest in that just like Mozilla and Apple both chose to invest in many web browsers that rendered HTML.

Web Standards

Next Steve started evangelizing open standards on the web. This is hypocritical and misguided on many fronts. First of all this can be applied to flash as a browser plugin, but not the flash packager, as like monotouch and Apple’s own xcode and objective-C . That isn’t the web that is an IPHONE application. In fact many of the applications that would have been developed with the flash packager would have nothing to do with the internet. many would have been standalone casual games that run totally offline. If he criticizes that for not being Open Web Standards, then there should neither be any appstore and objective-C applications and everything on the iPhone should be web apps.

Also apple’s stance on standards is quite a charade. They criticize Microsoft for not being standard compliant (while many of the standards derive from Microsoft’s own proprietary innovations to the browser over the years), while implementing nonstandard webkit-this and webkit-that extensions left right and center such as webkit-min-device-pixel-ratio. They do this  with the audacity of calling those extensions “emerging standards”.  This is no different than Microsoft’s own vector based enhancements and directX effect additions like filter:Alpha(style=2) . I actually have NO PROBLEM with apple doing this, nor did I with Microsoft. I just have a problem with Apple claiming one thing and doing another. The fact is innovation requires this. There are things of the traditional web that didn’t work well on the small screen and didn’t interface well with touch, and it is fine for Apple to innovate here.

Later in the letter Steve labels Flash as a kind of technology that is the Lowest Common Denominator. This is something that I say is true of Browsers, and also standards in general. Standards though with their value inhibit innovation. If this wasn’t the case then there would be no need for native iPhone applications and 3d games and top grade applications on the iPhone would be able to be made easily in a browser and would run fast.

As for his third point on reliability security and performance, I really can’t comment about flash as a web plugin, especially on a mobile device. Let’s come back in a year or so and see how it’s gone on Android. However as previously explained this is a moot point for Adobe’s native Flash compiler.

Battery Life, H.264 and animation performance.

Now for battery life. I don’t have any benchmarks, but based on my understanding the native applications shouldn’t wear any harder than an objective-C application. UI with rich animations will likely utilize the graphics hardware and that uses battery a lot faster. I notice all the time that my iPhones battery goes dead a lot faster playing games than using simple UI applications and this makes sense technical whether it’s being driven by Objective-C , flash or MonoTouch. Graphical intense applications use the graphical hardware as well as use the CPU more intensively than applications that are idle waiting for user input. He also compares flash rendering using CPU versus iPhones rendering using hardware And the battery life is hugely different. However flash on iPhone rendering H.264 would also use the hardware and the battery usage would be comparable.

On the H.264 front. Adobe had implemented that as its preferred high quality codec before the iPhone even came on the scene so I don’t know what Steve is referring to when he says “recently”. Also on the open standards front  Browsers (and apple) are choosing to use the non-open H.264 codec for video. This requires licensing and in the future even royalties (though that has recently been deferred for about half a decade). H.264 isn’t for everything either. Other codecs that flash uses are suitable for smaller sized videos with a lower frame rate.

Flash is more than just for playing videos. It’s for animation, and the speed of flash animation is FAR MORE PERFORMANT than the speed of HTML5 animation. There have been many tests done with simple to advanced animation that show this. A simple animation that may get 30 odd frames per second in flash compares to the best written HTML5 version with about 2 frames per second. So out of HTML or FLASH, which is the lowest common denominator?

Touch Touch Touch

Next up is the issue of Touch. Oh yeah Touch, it’s the reason I love my iPod touch and my iPad. Yes its true there is a lot of flash content that works with hovering and dragging. Hovering doesn’t work with touch, and dragging is something that the IphoneOS chooses to take control of and not pass through to the browser directly as it manages it for scrolling itself. This isn’t a flash problem this is content for one medium working on another medium. You have the same problems with a lot of Web content. Rich web application often use dragging and dropping, and hovering has been a mainstay of web design for many years. I’ve been frustrated on my iPad not being able to interact with standard compliant web pages that depend on hovering from showing things to interacting with menus. The truth is to work in a desktop and touch world developers of apps and webpages alike have to adapt and you can bet your bottom dollar that developers will update their flash apps to be touch friendly.

This is even truer for the iPhone packager. With that people are designing applications specifically for the iPhone and iPad and Adobe has exposed the touch functionality to be as flexible and as natural as any iPhones application. It’s true that these apps will have to be rewritten but why do that then instead of using “modern” technologies like HTML and JavaScript?

There are a few reasons. One you may only need to rewrite 5 to 10% of your application to make it an excellent touch application tuned specifically for the iPhone and running well on the iPhone compared to rewriting 100% to convert it to a web app, where the web app wouldn’t be in the app store, and it wouldn’t be able to use the full power of the Iphone, and as mentioned above its animation would be second rate. Besides Flash’s Action script is a close cousin to JavaScript and on the iPhone has the advantage of rather than being interpreted like JavaScript in Safari is, it is compiled to native code like Objective-C or C++ or C# with MonoTouch.

Third Party Layer argument. (API/SDK/Library/Engine)

Next is the last argument and the clincher but also flawed to its core. Steve argues that a third party layer ultimately results in sub-standard applications. Here I’m going to talk about tools and platforms and languages that go far beyond flash

First I’d like to separate “third party layer” from Language. Flash has a language ActionScript that gets compiled,

And then it will have its own libraries with its own UI layer, that basically just wants a surface to draw on, not unlike a HTML5 canvas, or a OpenGL surface that games use. It is not likely using Cocoa for its UI, because Cocoa isn’t the appropriate API for animation. OpenGL is. With existing iPhone applications  Some use CocoaTouch while others use the drawing APIs of the IPhone and others use OpenGL. Games typically use OpenGL. Some small applications that are little more than a pretty effect may call openGL directly and others especially games with have one or more layers in between. Graphical drawing engines, and game engines. Some of these game engines will have a higher level of abstraction and be larger and have more layers than flash will. This is just how complicated software is made and engineered and it’s ridiculous for Apple to prohibit this, and if they do they need to be consistent and pull the majority of games from the app store also.

In preventing flash, with 3.3.1 Apple is also incurring much collateral damage, whether intention or not. Frameworks like MonoTouch actually don’t have such a third party layer as they are designed to integrate naturally and effectively with CocoaTouch directly yet they are penalized because the “original language” before compilation happens to be something other than apple’s pet language – Objective-C.

There are many substandard applications in the App store currently , not because they use a third party layer, but because they don’t have the well luxury of having an engineered and tested third party layer already doing the difficult things for them. These applications crash and have memory leaks as web developers who may have experience in design tools like flash and html, and who can tinker some in a forgiving language like JavaScript come crash bang up against a systems programming language like Objective-C.

Objective-C is a language that stagnated for more than 20 years after losing the “C replacement” battle to C++. Don’t get me wrong I actually enjoy Objective-C and though adept at C++, I’d much rather writes Objective-C with COCOA than doing C++ with COM on windows. However restricting developers to languages and tools that don’t have the innovation and growth of programming languages over the last 20 years is ludicrous. There has been much innovation (such as memory management) and the truth is for certain types of applications it costs experienced developers more time and thus money to build the same thing with different languages, and time is money. Imagine if all web pages on the internet had to be made in Objective-C?

Steve also says that cross platform languages don’t let any one particular platform shine, and this is true to a point and will happen regardless. Certain sized developers will only put in enough effort to get their application running and won’t tweak it to take advantage of the unique aspects of each platform, but in a competitive world it doesn’t end here.

Let’s use games as an example. Large game companies put a lot of effort in building and tweaking their 3d engines and game engines for each platform they are on. They spent years and millions of dollars doing this and they want their games to utilize the unique features of each platform and push each platform to the limit. This may not be the case with casual games, but it is the case with major games. So do they write each game from scratch in a different language on each platform? No they don’t they write whatever is unique for each platform , and abstract their engine into one of these “third party layers” and have the bulk of the game be the same on each platform. They do go and add special features and tweak things per platform (and sometimes on PC per graphics card) to get things just right.

So let’s say I’m to write an application, if allowed using C# with Monotouch on Iphone OS, and I’m also going to write the same application for Android and Windows Phone 7. The common “business logic” and non-specific and non UI code I would write in C# classes that would be able to be reused on each version; however I’d write different UI for each. On iPhone I would use CocoaTouch, on Windows Phone 7 I’d use its Silverlight based UI and on Android I’d use something , I don’t know what but something different than the two of those. The UI coding may be about 20% of the development effort, but rather than having to make inferior applications but rewriting 100% of each platform, I have extra time and budget to tweak the app for the platforms I care about such as the iPhone. Also my application would really like to run in the background. Easy on Android, but for iPhone I’d write special code to use the new iPhone OS4 background abilities, and write special code for whatever mechanism Microsoft Releases for its mobile OS. I would do this because I want my app to be good and competitive. If I can’t do this, then I’d probably end up having to rewrite my app fully in Objective-C and do a half-baked job.

Challenging Steve’s conclusions.

Steve said that Flash is from the PC error era and for PCs and Mice. I think that was the context it was in, but you could say many aspects of the iPhone OS were from a unix server error and designed for servers. It’s a ridiculous point. CS5 Flash packager proves it can do touch and do it well, as can other languages and toolkits. Steve please don’t stifle our innovation, our creativity and our livelihoods. Steve also says that the mobile era is about Open Web Standards yet reality shows otherwise, it says it’s about proprietary native applications, whether for iPhone, android or windows mobile 7. How many iPhone targeted webapps are there compared to app store apps? How much time do iphone users spend in native apps compared to webapps (other than just generate website browsing)? Steve makes so many points against Adobe that just don’t stack up to reality or which could be thrown back in Apple’s own hypocritical face.

Class Action Lawsuit

I don’t know much about class action lawsuits nor what groups they can be based but it doesn’t seem that it would be right or legal for Apple to affect so many companies’ livelihoods and investments on a whim. I don’t know how many millions of dollars Adobe put into R&D for Flash Packager nor how much investment Novell put into MonoTouch , or their customers have put into building applications with MonoTouch. I know unity3D has invested years of R&D into their excellent game engine with great tools targeting the IPhones ecosystem with their many customers who have invested untold money and time building their games for the iPhone OS. Then there is the phoneGap, and Titanium companies and customers. the total sum of these developers , and companies compounds to significant losses and damages, and on top of that you can add the losses of their customers who bought applications on the app store which now probably won’t be allowed to be updated so people invested in apps via the appstore that are forced to not have a future. Maybe a class action lawsuit could be extended to appstore denials for many of the other arbitrary reasons why 1000s of apps have been denied or removed. Maybe the biggest anticompetitive aspect is the locked down app store and lawsuits could force apple to allow alternative or open methods of application delivery to the IphoneOS just as other operating systems like windows allows application distribution without approval (though vendors can choose to get windows  logo certified or such) through the internet, and various installer technologies, from usb sticks, from CD roms etc.

Antitrust Violations

Some people question antitrust as in that Apple isn’t a monopoly in the smartphone industry, but the thing is the iPhone ecosystem is large and is an industry in itself. If a company was a monopoly in say cable television you couldn’t say it wasn’t such because it’s not a monopoly in broadcasting and it actually only has a small share of the whole broadcasting industry. As such Microsoft is clearly a monopoly or near monopoly in the OS realm (and some other realms) but not in the computer software industry as a whole.

I’m glad to see that the government is at least looking into this. Which seems triggered by an Adobe complaint.

Another clause 3.3.9  (read about it at wired news ) which I wasn’t paying attention to but is in the same vein may be extra fodder against Apple in antitrust matters as again with the stroke of a pen they crush an already blossoming industry with players like admob that were valued at > $750 million . Individual apps or ad networks suddenly have a huge part of their existing product feature set (being able to analyze whether people clicked on their ads or not) disallowed so that apple’s new iAd platform can have exclusive dibs.

Final thoughts

A huge aspect is how will Apple (and others)  interpret this & how consistently will it be enforced, however as software development companies we can’t trust such risks based on the mood of Apple from one day to the next.

and by the way , i don’t really personally care if flash packager gets accepted on iphone. I don’t think i will develop for flash again, but i am fighting for the freedom for all developers to be able to use the tools of their choice that work and the freedom to not have your livelihood threatened by companies like Apple abusing their position but changing rules on their whim. This is professional software development not a 1st grade playground where a bossy kid just keeps changing the rules of the game so they are the only winner.

This is only a draft and I’m sure I’ve made many spelling and grammatical errors and probably a few times missed a word negating my meaning entirely. All comments and corrections are welcome.

Also here i want to gather a list of links to all good commentary on this issue. Links and suggestions would be appreciated. I’ll start with a few

Steves Letter – http://www.apple.com/hotnews/thoughts-on-flash/
Miguel De Icaza – http://tirania.org/blog/archive/2010/Apr-28.html

More links to come, i need to get to bed for now.

Karl Prosser

Posted in Powershell | 9 Comments »

« Previous Entries