Tuesday, October 29, 2013

Software Patents = Crazy Talk

Rep. Goodlatte, my representative in congress, has been working on fixing the problems with US Patent Law. I just emailed him the following:

Thank you for working on reforming our blighted patent system. Merely controlling litigation is not enough. You mentioned frivolous and speculative patent lawsuits, but you did not identify the deeper problem with software patents.
Software is written. Software should be protected under copyright laws not patent laws. Copyrights protect exact wording, but do not prevent people from speaking, thinking or writing about those ideas. Just like literate people can read ideas in good books, literate software engineers can read ideas in software. Just as literate people should not copy a book word for word and take credit for writing it, software engineers should not copy a computer program word for word and take credit for writing it.
Software should not be patentable. Think about these: A bookbinding, a new way to make paper, a new computer case, and a revolutionary computer screen. These can be patented, but the ideas on the pages of a book and the ideas in each line of software code are only thoughts and ideas. Patenting an idea is like trying to control how people think, it's like trying to control the newspapers saying that there can only be one republican newspaper and one democratic newspaper. Preventing the spread of thoughts and ideas is not constitutional.
Allowing software patents is like saying we don't really believe in the right to believe, think, or speak. Allowing software patents is fundamentally wrong. 
Please champion legislation to protect software the right way: with copyrights, not with patents.

Tuesday, August 6, 2013

Figuring out TDD

I want to use TDD in my GSoC project. Tests are important, and the benefits of testing are worth it.

Now, my only problem with TDD is, I'm not quite sure how to do it. Oh, I've got the mechanics in place (Travis is set up and ready to eat my github repo, and I think I've got phpunit setup locally. Heck I even have Jenkins on my local machine if I could ever get it configured right.), but whenever I go to write unit tests, I feel like I'm staring at a blank page in an old fashioned typewriter.

t  o  w  e  r
I feel like I'm staring at a blank page in an old fashioned typewriter. (Image from starside on flickr)
For a long time, I think my problem was an incomplete design. I knew I wanted to take stuff from a boilerplate, then "process it somehow", then put it in a derivative package. But I didn't know what that "somehow" looked like.

Well, I've figured out the main parts of that process now. I know what I want my API to look like (within PHP). So, I take my first example, and go line-by-line to make it work.

Loading Gist ....

So, let's take part of line 2:

new BlobQuery('Cognifire.SweetSitePackage');


How do I test this? Do unit tests test constructors? Is this a unit?

And so I'm back at that blank page again. I'm not quite sure what unit I'm testing. The constructor doesn't return anything, it just sets up the object. Should I add getters and setters for what should ultimately be protected properties just so that I can test that they are initialized correctly? That seems rather odd.

But TDD says don't write a line of code until you've written a failing test, so I feel stuck.

How do you approach TDD? Unit testing? What questions do you ask yourself to get past the stupid blank page?

Monday, July 15, 2013

BuilderFoundation BlobQuery

Blob: A file, or a snippet/section of a file, or syntax-tree like thing. Typically, a blob requires a special parser.

BlobType: A blob has a type so that it can be handled by the appropriate parser.

SubBlobs: A blob in another blob.

BlobType-SubType: BlobTypes are not restricted to just the main blob types, but may define subtypes as well to make working within the syntax tree easier. A SubType is separated by a dash (maybe I should use a dot as the separator like NodeTypes does in TYPO3CR. What do you think?)

Example BlobTypes include: FluidBlob, HtmlBlob, PhpBlob, YamlBlob, TypoScriptBlob. I believe the packageBuilder will need an additional DomainBlob that doesn't map to any particular media-type. A Blob is essentially a generalized syntax tree, and a DomainBlob would be used to create PhpBlobs, it's just a more specialized/focused view of the information.

Example SubTypes (if I match the syntax tree exactly):

  • FluidBlob
    • FluidBlob-Array
    • FluidBlob-Boolean
    • FluidBlob-ObjectAccessor
    • FluidBlob-Numeric
    • FluidBlob-Text
    • FluidBlob-ViewHelper.
  • PhpBlob
    • PhpBlob-Class
    • PhpBlob-Function (PhpBlob-Method within Class)
    • PhpBlob-Interface
    • PhpBlob-Namespace
    • PhpBlob-Property
BlobQuery: This provides a context for FlowQuery. You create a new BlobQuery with a given path (typically a package path), and BlobQuery scans for files (optionally filtered by type), creates a Blob object for each of them, and adds them to an initial set of objects before returning a new FlowQuery instance that's using the set of Blobs.

OK, so here's a portion of the UML diagram I've been creating (in ArgoUML) to figure out what all needs to go in BuilderFoundation.


The OperationResolver expects simple values for priority, shortName, and Final, but I want to have one Operation class, BlobTypeSpecificOperations, that calls a variety of methods on the Blobs. To make this work, I add a BlobTypeSpecificOperationsAspect that calls a specialize initializeObject right after OperationResolver->initializeObject() gets called. This grabs the Cognifire.BuilderFoundation.BlobTypeOperations configuration and adds all of the registered blob operations to the list of operations. That means that if a blob has a special operation that only works for that BlobType, then add it as a method in the Blob itself (makes code organization feel better), and register that method as a BlobOperation in the Settings.yaml file. Whenever that operation gets called, it will go through BlobTypeSpecificOperations->evaluate() which will call the registered method on the blob for that operation.

The reason this is important, is you'll select a set of blobs with BlobQuery/FlowQuery, and then do some operation, and it will do that operation on all of the Blobs.

AOP is awesome!

Saturday, July 6, 2013

GSoC Notebook

I wanted to show that I'm still working on this, and a video seemed like the easiest way to show off my notes to the world. Enjoy. Let me know if you have any questions or want to know about something in my notebook.



Friday, June 14, 2013

Changing OpenRC colors to use Solarized

So, after switching my terminals to use the solarized color scheme, I was dismayed to discover that alot of apps don't like it when you change the ANSI colors.

OpenRC commands are no exception: rc-status, rc-config, and rc-service all tried to use the bold colors which have been reassigned, so the output is downright ugly.

I just went sifting through the OpenRC sources, and discovered a little gem: EINFO_COLOR is an environment variable that does more than turn color on or off. No, that little sucker allows you to redefine which ANSI colors it will use for output.

Here's what I do to make it use solarized. I put the following line in /etc/bash/bashrc (because everything is solarized, not just my user):

export EINFO_COLOR="good=2;0:bad=1;0:warn=1;1:hilite=7;1:"

This sets my colors to:
  • good is green
  • bad is red
  • warn is orange
  • hilite is base3
So, EINFO_COLOR lets you change the colors (all lower case): good, warn, bad, hilite, and bracket. You can't change the normal text color.

Each of the colors is a pair of two numbers

  • The first number is the ANSI Color (0-7)
  • followed by a semicolon (;)
  • followed by whether or not it should use the "bold" ANSI Color (0 is normal, 1 is "bold")
  • followed, by a colon (:) which serves to 'end' the number and separate the variables in the string
So that means that Solarized colors would be specified like this:


SOLARIZED HEX     16/8 TERMCOL   EINFO_COLOR
--------- ------- ---- -------   -----------
base03    #002b36  8/4 brblack   0;1:       
base02    #073642  0/4 black     0;0:       
base01    #586e75 10/7 brgreen   2;1:       
base00    #657b83 11/7 bryellow  3;1:       
base0     #839496 12/6 brblue    4;1:       
base1     #93a1a1 14/4 brcyan    6;1:       
base2     #eee8d5  7/7 white     7;0:       
base3     #fdf6e3 15/7 brwhite   7;1:       
yellow    #b58900  3/3 yellow    3;0:       
orange    #cb4b16  9/3 brred     1;1:       
red       #dc322f  1/1 red       1;0:       
magenta   #d33682  5/5 magenta   5;0:       
violet    #6c71c4 13/5 brmagenta 5;1:       
blue      #268bd2  4/4 blue      4;0:       
cyan      #2aa198  6/6 cyan      6;0:       
green     #859900  2/2 green     2;0:       

Wednesday, June 12, 2013

Tech Buzzword Bonanza

I made this awhile ago while studying a bunch of different tech topics. I referred back to it today, and ended up recreating it in VUE so that I could update it. The original version was in a trial version of Lucid Chart. I've updated it with a few more terms from Domain Driven Design and TDD/BDD. Maybe someone else might find this helpful.
Tech Buzzword Bonanza

Monday, June 10, 2013

Scattered design thoughts

So, I have notes scattered everywhere and I'm somewhat lost. I'm using this post to try and collect my notes, and get a better idea of where I am and where I'm going. Though you're welcome to browse through this, I don't expect these notes to make sense to anyone other than me.



BuilderFoundation provides a MetaModel for packages that other Builders will extend.

A Package can be built like FormDefinitions from TYPO3.Form
  • FormDefinitions have:
    • finishers <array>
    • processingRules <array>
    • elementsByIdentifier <array>
    • eleementsDefaultValue <array>
    • formFieldTypeManager <injected class>
    • validatorPresets <array>
    • finisherPresets <array>
    • setOptions (stuff that works with info from a YAML)
      • setRendererClassName
      • setRenderingOption
      • createFinisher
  • The FormFactory builds FormDefinitions
  • Use the name "presets" which would work as an options layer in general, or a "themes" layer in TemplateBuilder (a preset is a name + configuration; or iow it is a named set of configuration)
  • Based on YAML files
  • Using a yamlPersistenceManager
YAML files
  • Use superTypes inheritance concept (like in Forms and TYPO3CR: NodeTypes.yaml) to allow for things like mixins
  • Always get converted to arrays
  • considered using TypoScript, but YAML seems to fit how I'll use this better. (YAML is for data serialization. TypoScript helps in processing things)
  • YAML processors should always have at least one of dump() or load()
  • Each package has a configuration file in YAML
  • boilerplates and settings repositories should be added from the yaml (Cognifire\BuilderFoundation\boilerplateRepositories & derivativeRepositories)
  • Current configuration files
    • Settings.yaml
    • Routes.yaml
    • Objects.yaml
    • Policy.yaml
    • PackageStates.php
    • Caches.yaml
    • Views.yaml
  • It would be nice to be able to breakup boilerplate configurations so that there's one preset per file (or somethin like that). <whatever base name>.<preset name>.yaml
  • Will need a schema:
AbstractPackage: Boilerplates and Derivatives
  • not packageKey identified, but w/ UUID because packageKey might change several times during package build process
  • What gets stored in the package object is metadata about it's creation
    • a declarative set of steps--if you will--to allow the builder to recreate the same derivative but with another package key
    • Only part of this can be found out by parsing directory structures.
    • Instead, you
      • list Packages/<target repo>/*
      • read each <package>/Configuration/<yaml file>
  • Yaml file names (not satisfied with these names)
    • Themes.yaml (Builders might want to provide their own yaml file, like the templateBuilder where the word "themes" makes a lot of sense)
    • Possible names in Boilerplates:
      • Builder.Boilerplate.yaml
      • Boilerplate.yaml
        • Declared components (all available)
      • Boilerplate.presets.yaml
      • Boilerplate.presets.<something>.yaml
    • Possible names in Derivatives:
      • Builder.Derivative.yaml
      • Derivative.yaml
      • Boilerplate.Integrated.yaml
        • Declare which components were used and from where without introducing a dependency on the boilerplate
      • Builder.Template.yaml or Builder.Package.yaml
        • contains the presets or the final configuration, how all of declared components were put together
        • Builder specific?
    • Boilerplate.yaml and Derivative.yaml can be a collection of YAML files to keep the component definitions in the same folder as the component. Everything in that Boilerplate would apply only to that path. With one exception: Resources/Private/[Boilerplate || Derivative].yaml applies to the whole package. They should be restricted to the Resources folder, though, so that we don't have YAML files in the Classes/ or Tests/ folders. Boilerplate.yaml and Derivative.yaml should also not be in Settings/ as that is reserved for Presets.*.yaml for builder stuff as well as other configuration that is not builder-related.
    • Basically, this means that Boilerplates will store the snippets they use to build files in the Resources folder.
  • Boilerplate vs Derivative
    • Package Repository (Boilerplate vs Application)
    • Derivative
      • Root files (composer.json...)
      • Resources
      • Configuration
      • Documentation
      • Classes
      • Tests
      • Scripts
      • Migrations
      • Meta
  • Yaml files, rethought
    • <package>/Resources/Private/Boilerplate.yaml
      Declares which components/resources are available in boilerplate including:
      • Which builder is required to work with a particular set of files. Or maybe they would declare filetypes like x.html is fluid and y.html is handlebars so that the appropriate Builder can be used, and the Builder would say which filetypes it works with)
      • A versioning "namespace" of sorts, so that a boilerplate can include multiple versions of layouts/templates/partials (thinking of TwitterBootstrap v2 and v3). This would assist the migration service
      • Perhaps a list of presets that are available in the Boilerplate (though that should probably be based on what is in the Settings/)
    • <package>/Resources/Private/Derivative.yaml
      • Declares which components & presets have been used
        • from which boilerplate
        • and which boilerplate version (to assist with migrations)
      • Perhaps a list of which manual changes have been detected
      • This file would have the Eel selectors to say "insert [component] at [location] in [file]" including components from boilerplates and components that are added manually. This should be verbose enough that a Builder could regenerate the templates from the boilerplates (for the custom components [the 'changeset in Boilerplate math], maybe the builder could pull them out and store them in another Resources/Private/ folder so that it can keep track of manual changes.)
      • Though this should be human readable, only Builders will edit it. I can imagine people tweaking an Eel statement. But most of the file is for Builder metadata persistence.
    • <package>/Settings/
      Presets.[BuilderSpecific].[PresetName].yaml

      A preset configures a set of components to work together. This is the Builders' "options" layer. It does not define how the files are combined. That belongs in the Boilerplate.yaml (for what can be combined) or Deriative.yaml (for what has been combined) files.
      Should the BuilderSpecific part be singular or plural? You can have multiple presets in a Presets.Builder.yaml file, or break them out into individual Presets.Builder.Preset1.yaml and Presets.Builder.Preset2.yaml files.
      Someone could edit a Preset manually and use the Builder to make the change in their templates. These should be human-friendly. They would have to fire up the Builder to make the builder adjust whatever files are built with that preset (like changing a color in a LESS file).
      Examples of possible uses per builder (just examples, most are not part of GSoC project):
      • PackageBuilder
        • Presets.Package.CMS.yaml
        • Presets.Package.Flow.yaml
        • Presets.Package.Symfony.yaml (example extension of PackageBuilder)
      • TemplateBuilder
        • Presets.Theme.yaml
        • Presets.Theme.FixedLayout.yaml
        • Presets.Theme.AwesomeGreen.yaml
        • Presets.Theme.MyThemeName.yaml
        • Presets.Fluid.yaml (for stuff that doesn't quite fit the term "Theme"
      • TypoScriptBuilder
        • Presets.TypoScript.yaml
      • EmberBuilder or JavaScriptBuilder (Works with JavaScript stuff like Ember and Handlebars)
        • Presets.Ember.yaml
        • Presets.Ember.Handlebars.yaml
        • Presets.Handlebars.yaml
        • Presets.JS.yaml (maybe everything could be Presets.JS.*.yaml like Presets.JS.Ember.yaml and Presets.JS.Handlebars.yaml)
      • FormBuilder (if it switches to using BuilderFoundation at its core)
        • Presets.Form.yaml
        • Presets.Form.Cli.yaml
        • Presets.Form.Bootstrap.yaml
      • TranslationBuilder (works with .xlf files)
        • Presets.Translation.yaml (not sure how a TranslationBuilder would need Presets, but it's possible)
      • SchemaBuilder (a Resource that needs to be built. Different Builders might want to create a schema for what is allowed in their Presets.[Builder].*.yaml files, and they might not want to craft the schemas by hand)
      • OntologyBuilder/TaxonomyBuilder (Not sure this one will work with packages or boilerplates, but, the Builder concept still applies)
  • Yaml file contents Boilerplate vs Derivative (extendable yaml schema)
    • Boilerplate
      • relevant builder (like template builder)
        • components that can be built
          • include[superType]
          • Variations of each component
          • Options that apply to each component
      • presets
        • components 1,2,5
          • variations such and so
          • options
      • TemplateBuilder: (example specific builder)
        • Declare what is avilable
          • Components:
            • Variations
            • Options
          • Variations
          • Options (Theme in TemplateBuilder)
            • color1:
            • color2:
            • width:
        • Presets are pre-configured defaults / collections of components and options
          • Presets / <presetname>
            • components: 1, 2, 3
            • variation: A, B
            • options
    • Derivative
      • Has one preset that lists which
        • boilerplate components are in use
        • how they are configured
        • what options are set
      • Boilerplate.Integrated.yaml
        • declares components used from each boierplate
          • copied from boilerplate w/ boilerplate version
Spl*Iterators [Directory, FileSystem, Glob]:
  • Relationships
    • GlobIterator extends FileSystemIterator extends DirectoryIterator
    • RecursiveDirectoryIterator extends FileSystemIterator as well
    • GlobIterator is one level w/ glob pattern search
    • DirectoryIterator is one level
    • FileSystemIterator is just like DirectoryIterator but with flags that give more control over what current and key return.
    • RecursiveDirectoryIterator does many levels
  • Interesting FileSystemIterator Flags
    • ::CURRENT_AS_PATHNAME
    • ::KEY_AS_PATHNAME
    • ::KEY_AS_FILENAME
    • ::FOLLOW_SYMLINKS
    • ::NEW_CURRENT_AND_KEY (KEY_AS_FILENAME & CURRENT_AS_FILEINFO)
    • ::SKIP_DOTS
    • ::UNIX_PATHS (I'll want this one)
    • Current could return Pathname, or Filename or Fileinfo (which is a SplFileInfo object)
    • Key is just a numeric array key
  • SplFileInfo interesting methods (also available on DirectoryIterator and FileSystemIterator)
    • getBasename (can omit a suffix from path & filename)
    • getFilename
    • getPath (w/o filename)
    • openFile (creates SplFileObject to iterate ovver a file w/ fwrite, fpassthru...)
    • getRealPath (resolve links)
    • getExtension
    • getType (file, link, dir)
  • Streams
    • file:// -- for file access
    • glob://*.png -- for listing dir contents that match the glob
    • data: -- to encode stuff straight in files and treat it as a file/stream (RFC 2397)
      • data:text/plan,$data
      • data:text/plain;base64,$data
      • data:image/jpeg;base64;$image
    • resource:// -- flow specific only for stuff in resources of a particular package
      • The purpose of this is not to hide that something is a file, but to hide where it is stored (so that Flow can do the linking magic with all the public stuff in the Web/_Resources folder
Persistence
  • Flow injects the persistenceManagerInterface
  • There's no way to say which one flow will use, instead it is specified in objects.yaml (doctrine by default)
  • Mutliple concurrent Persistence backends won't be available until Flow 2.2 (or Flow 3 depending on how backwards compatible it is
    • define on repository basis what kind of DB to persist it in
    • This is not implemented yet due to lack of funding
    • I would rather reuse the flow persistence stuff where it makes sense, but I have to decouple everything until this is implemented. I'll copy lots of stuff to make it work. The thing is, a DB doesn't make any sense in my packages, even though I'm persisting stuff, the code assumes that persistence is always to a DB.
    • workaround is to put persistence stuff in the repository and not use @Flow\Entity and the like
  • "Models do not know (a lot) about Persistence (internals)"
  • Repository responsible for:
    • Saving object
    • persisting changes to object throughout lifetime (update DB as needed)
    • provide QL
      • handle DB retrieval
      • ensures only one instance in memory
    • provides the aggregate root
  • Comparing Radmiraal.CouchDB (doctrine branch) with normal doctrine persistence
    • @ODM\Document instead of @ORM\Entity or @Flow\Entity
    • replaces persistence manager w/ document manager
    • queries
      • no query on arbitrary properties
      • drops queries in favor of lucenQueries
      • setQueryMatchValue
    • both use persistenceManager
      • ->getObjectByIdentifier in generic
      • ->getIdentifierByObject in radmiraal
    • persistenceManager vs documentManager method names
      • add; persist
      • update; merge
      • remove; remove
      • createQueryForType; [createLuceneQuery, createNativeQuery, createQuery]
  • Doctrine's PersistenceManager uses the Annotations Driver
    • Annotations
      • Entity
        • map the repository / set CustomRepositoryClass
        • markReadOnly
    • loadMetaDataForClass
      • evaluatePropertyAnnotations
        • maps to column names, OneToOne, OneToMany, ManyToOne, ManyToMany
      • evaluateOverridesAnnotations
      • evaluateLifeCycleAnnotations
        • public methods
          • PrePersist
          • PostPersist
          • PreUpdate
          • PostUpdate
          • PreRemove
          • PostRemove
          • PostLoad
          • PreFlush
      • isTransient (yes if not entity or value object)
    • I want to use Flow/Validate
    • PersistenceManager fires
      • Yaml Configuration
        • All combined/cached like views.yaml

How other things interact w/ files
  • Parts of flow that work with files
    • Reflection uses cache to interact w/ Files
    • Fluid uses cache in compiler, and strings get passed to parser (it doesn't work w/ files)
    • TypoScript also parses strings, not files
    • Kickstarter
      • uses $templatePathAndFilename = resource://TYPO3.Kickstart/Private/...
      • shoves into renderTemplate()
      • then generateFile()
        • File::createDirectoryRecursviely
      • uses reflection for php files
      • hard codes important paths
        • Classes
        • Tests
        • Resources
      • Validate PackageKey ; PackageManager->isPackageAvailable
  • TYPO3\Flow\Utility
    • Environment
      • $this->environment->getPathToTemporaryDirectory()
    • Files
      • ::getUnixStylePath($cacheDirectory)
      • ::concatenatePaths($cacheDirectory)
      • ::readDirectoryRecursively($cacheDirectory)
      • ::createDirectoryRecursively($cacheDirectory)
      • ::emptyDirectoryRecursively($cacheDirectory)
  • php funcs
    • file_exists($pathAndFillename)
    • unlink($pathAndFilename)
    • file_get_contents($pathAndFilename)
    • file_put_contents($tempCacheEntryPathAndFilename, $data)
    • rename($tempCacheEntryPathAndFilename, $newPathAndFilename)
    • filesize($cacheEntryPathAndFilename)
    • filemtime($file)
    • new \DirectoryIterator ($this->cacheDirectory)
      • ->valid()
      • ->next()
      • ->isDot()
    • glob($pattern) find pathname matching the pattern
    • $fileHandle=fopen($this->logFileUrl, 'ab')
    • dirname($logFileUrl)
    • is_dir($)
    • is_link($)
    • stream_get_meta_data($fileHandle)
    • fclose($)
    • chmod( , )
    • touch()
    • fputs()