Monday, March 29, 2021

Strategic 1.0.0

The Strategic gem (Painless Strategy Pattern in Ruby and Rails) has been updated to better match the authentic Gang of Four Strategy Design Pattern, and has been finalized as 1.0.0 as a result. It now allows setting strategies via the `#strategy=` attribute writer method, and then dispatch strategic model method invocations automatically to the configured strategy. It also provides the option of setting a `default_strategy`, getting current `strategy`, and getting strategy `context` (aka strategic model as per the GOF Design Pattern).



Learn more at the project page:

https://github.com/AndyObtiva/strategic

You may also read:

Sunday, March 28, 2021

Glimmer DSL for SWT 4.19.0.0 Halved Startup Time

Glimmer DSL for SWT just had the biggest release in quite a while in version 4.19.0.0:

  • Upgrading to the newly released SWT 4.19
  • Revising scaffolding to generate proper-Ruby-namespaces for Model and View just as done in the recent Tetris sample (instead of just models/views non-namespace directories like Rails does), thus better adhering to the Ruby way of simply relying on require statements in establishing dependencies (distancing itself from the often decried Rails way of autoloading)
  • Supporting `c_combo`, `c_tab_folder`, and `c_tab_item` variations on the `combo`, `tab_folder`, and `tab_item` widgets to permit further customizations to font/background/foreground/height and display of an unlimited number of tabs with a dropdown.
  • Adding two new samples "Hello, C Tab!" and "Hello, C Combo!"
  • Finally addressing the slow startup time of the `glimmer` command, which used to start jruby twice, the first time to determine what options were most appropriate depending on the platform you are on (e.g. Mac requires the -X-JstartOnFirstThread switch) and then running jruby again to start the glimmer app. That ended up wasting a lot of startup time, which fortunately Glimmer packaged (released) apps did not suffer from (they do not rely on the glimmer command given they are native-executable packaged). Also, obviously this was not a truly serious issue given that software engineers could always run glimmer apps directly with jruby anyways, yet just a minor inconvenience. Thankfully, this has been eliminated by relying on JRuby environment variables to set options at gem setup time (it now has a new command `glimmer-setup` for the Mac only where needed), cutting down the glimmer command startup time across the board in half (from about 20 seconds to 10 seconds on an old 2015 MacBook Pro... should be much faster on newer machines)

About the last point, a further thing to note is there are many solutions to reduce the jruby startup time or even eliminate it in Glimmer apps during both development and production. I have been relying on such solutions even if I did not blog about them before, which is what has been keeping me pumping out Glimmer DSL for SWT apps at light speed as everyone would attest by reading my frequent blog posts. 

Please keep in mind first of all that for most business apps, it is not a true issue since users tend to start the app and leave it on all day long, and Glimmer DSL for SWT performance via JRuby is very fast after app startup. Glimmer DSL for SWT productivity, maintainability, and extensibility benefits way outweigh any costs associated with startup time in the enterprise.

That said, in development, it would be useful to reduce the feedback cycle or even eliminate it, and in production, it would be nice to bring up an app instantly if a user uses it often and shuts it down immediately afterwards (still, that is not the common case in the enterprise, which is why I have not given this much attention before).

Regarding development, here are your options:

  • Use Gladiator (Glimmer Editor), which enables you to run any Ruby file instantly (with zero delay) via CMD+R, including Glimmer GUI DSL code. You can see a demo of that on the Gladiator project page (included below).
  • If you prefer another Ruby based Editor/IDE (e.g. Redcar or Arcadia), write a plugin to preload the Glimmer DSL for SWT library (and start with -X-JstartOnFirstThread on the Mac) if needed (should not be needed with Redcar since it runs on SWT too). That way, you should be able to run Glimmer GUI apps instantly as well.
  • Run your code in the included Glimmer Meta-Sample editor, which starts it instantly.
  • Use GIRB (Glimmer IRB), which enables trying out snippets of Glimmer GUI DSL code and seeing app GUI materialize instantly. GIRB is mostly well suited for running small snippets, so it is great for experimentation and learning with the Glimmer GUI DSL.
  • Try passing the `--dev` JRuby option to the `glimmer` command (can accept any jruby option and passes it through), which according to JRuby command documentation, prioritizes startup time over long term performance.


Otherwise, concerning production, you have these options:

  • Build your app as a system tray app (Tray is featured in SWT Widgets). That way, the app stays in the background at all times even if its main window is closed, and can be brought back up instantly.

  • Build your app as a daemon app (aka service or server/client architecture) so that if you close the GUI, the app merely closes the client window while continuing to run in the background. When you start the app again, you have a shell runnable or C executable (can be generated for free with Platypus) that simply alerts the daemon to show its window instantly. The communication mechanism can vary, including DRb (aka druby or distributed ruby run via C Ruby to start fast and connect to the JRuby daemon) or file-based communication (dropping a file somewhere in the user directory). I have tried the DRb approach successfully in the Glimmer Timer sample "glimmer-app-type-client-server" branch
  • Use Nailgun, which provides similar daemon support to the last idea, but at the JVM level (I have successfully conducted an experiment with this)
  • Use Drip, which spins an extra JVM ahead of time when you start an app and keeps it running for the following run, which starts instantly (I have not tried this yet, but if you try it yourself, please blog about your experience and share here in a comment).
  • Consider contributing to the new Glimmer DSL for Tk early alpha project, which aims to bring Glimmer DSL for SWT niceties to C Ruby (aka MRI) and thus has a much faster startup time than the JVM, albeit keep in mind the trade-offs of Tk like being less enterprise-grade than SWT and requiring Ruby recompilation on every platform, but nothing could stop a highly motivated open-source software engineer from changing that, I'm sure of it.

In any case, here are the new Hello Samples for `c_combo`,  `c_tab_folder`, and `c_tab_item`

Hello, C Combo!






Hello, C Tab!






If you ever have questions concerning Glimmer DSL for SWT, do not make assumptions as it is always a better idea to contact me via Gitter, Blog Comments, or GitHub Issues given my deep experience and expertise with desktop development, JRuby, SWT, and Glimmer/Glimmer DSL for SWT.

Happy Glimmering!

Saturday, March 20, 2021

Strategic 0.9.1 Strategy Matcher/Alias/Exclusion

The Strategic Ruby gem (Painless Strategy Pattern in Ruby and Rails) just had a new release in 0.9.1 (as well as 0.9.0), adding the following features:

  • Strategy Matcher: custom matcher support for selecting strategies (e.g. implement a fuzz matcher for picking a strategy by full string name or any partial match in case it is typed by a user)
  • Strategy Alias: specify an alias for selecting a strategy (e.g. car strategy has "sedan" as an alias)
  • Strategy Exclusion: exclude a strategy from a matcher (e.g. partial match on 'USA' and 'US', but not 'U')
To give you some background, the Strategic Ruby gem was mostly born out of work I did last year at Chronogolf by Lightspeed, a golf course management web app built in Ruby on Rails, where we had countless of strategies for customizing models, especially in relation to quotes, pricing, payments, memberships, and golf course tee time reservations. 




It is currently used in the DCR Programming Language, implementing language commands (Command Pattern) as a special case of Strategy Pattern, with auto-inference of strategy names from command file names by convention.

Strategic enables you to make any existing domain model "strategic", externalizing all logic concerning algorithmic variations into separate strategy classes that are easy to find, maintain and extend while honoring the Open/Closed Principle and avoiding conditionals.

In summary, if you make a class called TaxCalculator strategic by including the Strategic mixin module, now you are able to drop strategies under the tax_calculator directory sitting next to the class (e.g. tax_calculator/us_strategy.rb, tax_calculator/canada_strategy.rb) while gaining extra API methods to grab strategy names to present in a user interface, grab strategy classes to select, and/or instantiate TaxCalculator directly with a strategy from the get-go.


You may also read:

Saturday, March 13, 2021

Glimmer Gets Its First Official Custom Shape Gems

Glimmer DSL for SWT recently added support for Custom Shapes, which are reusable graphical constructs akin of Custom Widgets (reusable widget constructs). Glimmer DSL for SWT just got its first official custom shape gemsglimmer-cp-bevel, providing the `bevel` keyword, and glimmer-cp-stickfigure, providing the `stick_figure` keyword. They are covered below.

Bevel 

This represents a bevel square custom shape that can have various colors and sizes, and you only need to set its base color for it to figure out the rest. It is customizable via its API.


Currently used in Glimmer Tetris.


Glimmer GUI DSL Code Example:


Tetris icon image produced:


Stick Figure 

This represents a stick figure custom shape that can have colors and sizes, and you only need to set its base size for it to figure out the rest for the stick figure head, torso, arms, and legs. It is customizable via its API.

Currently used in the upcoming DCR project


Glimmer GUI DSL code for Hello, Stick Figure! Sample:

Hello, Stick Figure!

Happy Glimmering!

Friday, March 12, 2021

Draw2D Spike in Glimmer DSL for SWT

The Eclipse IDE ecosystem includes a highly advanced 2D graphics library called Draw2D (comes as part of GEF, the Graphical Editing Framework), which rests on top of the SWT Canvas widget.

I got a chance to play around with it today and even do a spike in Glimmer DSL for SWT for supporting a Draw2D DSL. I finished a rough version in about an hour or two. Check out the samples I created below.

Spike 1 (Rectangle and contained Polygon + Drag & Drop Movement):

Screenshot:





Spike 2 (Rectangle and contained Ellipse + Drag & Drop Movement):

Screenshot:





Spike 3 (Multiple Rectangles and Ellipses within a GridLayout of 8 columns + Drag & Drop Movement):

Screenshot:





Wednesday, March 10, 2021

Nebula - Glimmer Custom Widget

Glimmer DSL for SWT's got a new custom widget (or more accurately 55+ new custom widgets): Nebula

The Nebula Project is a collection of enterprise-grade high-quality SWT (Standard Widget Toolkit) custom widgets, which are made available for use with Glimmer DSL for SWT in this Ruby gem. They cover many different widgets, such as breadcrumbs, wizard step bars, shelf groups, geo maps, and even oscilloscopes.

Thanks to Glimmer's unique DSL Auto-Expansion feature, its GUI DSL automatically grows when new custom widget libraries are imported, even if they were originally written in Java, like the Nebula Project.

Below is the list of custom widgets newly added by the Nebula Custom Widget gem.

LED Display

LED Display

Badged Label

Badged Label

Oscilloscope

Oscilloscope

Custom Date Time

c_date_time

PShelf

p_shelf

Gantt Chart

gantt_chart

Used in Are We There Yet?

Are We There Yet

Gallery

Gallery

Grid

This is a richer alternative to the table widget.

Grid

Paper Clips

Paper Clips

PGroup

PGroup

Rich Text

This is a richer alternative to the styled_text widget with some caveats (uses the browser widget behind the scenes).

Rich Text

Geo Map

Geo Map

Table Combo

TableCombo

XViewer

This is a richer alternative to the tree widget.

XViewer

Transition

Transition

Breadcrumb

Breadcrumb

Checkbox Group

Checkbox Group

Column Browser

Column Browser

Dialog

This is a richer alternative to the built-in dialog widget.

Dialog

Dual List

Dual List

Header

Header

Heap Manager

This shows memory usage in an application's Java Virtual Machine.

Heap Manager

Login Dialog

Login Dialog

Multi Choice

Multi Choice

Notifier

Notifier

Preference Window

Preference Window

Prompt Support

Prompt Support

Range Slider

Range Slider

Rounded Toolbar

Rounded Toolbar

Star Rating

Star Rating

Text Assist

Text Assist

Tip of The Day

Tip of the Day

Titled Separator

Titled Separator

Calculator

Calculator

Horizontal Spinner

Horizontal Spinner

Launcher

Launcher

Panels

Panels

Switch Button

Switch Button

Progress Circle

Progress Circle

Nebula Slider

This is a richer alternative to the built-in slider widget.

Nebula Slider

Split Button

This is an alternative to the combo widget.

Split Button

Rounded Checkbox

This is an alternative to the checkbox widget (aka check or button(:check) widget).

Rounded Checkbox

Floating Text

Floating Text

Password Revealer

Password Revealer

Custom Tree Combo

Custom Tree Combo

Step Bar

Step Bar

Chips

Chips

Carousel

Carousel

Font Awesome

Font Awesome

Rounded Switch

Rounded Switch

Nat Table

A higher-performant alternative to the built-in table widget.

Nat Table


Glimmer DSL for SWT is more than feature-complete. It is enterprise-grade-complete! As such, Glimmer absolutely outdoes its competition in the Ruby world, and I would dare say the entire desktop development world. No other GUI library comes even close to what Glimmer DSL for SWT offers in terms of productivity, readability, maintainability, and extensibility. Think of it like this! While some other libraries are still learning how to wear shoes, Glimmer DSL for SWT has learned to run, drive a car, fly an airplane, launch rockets into space, and zoom at light speed!!! The sky is the limit with Glimmer DSL for SWT. You could think up any desktop application custom widget or custom shape, and your wish is Glimmer DSL for SWT's command with the absolute minimum syntax possible! Go ahead world and make trillions of dollars in service of others by leveraging Glimmer

I envision Glimmer DSL for SWT to eventually have thousands if not millions of custom widget gems made by the community. As long as they follow the “glimmer-cw-name-namespace” convention, they can be discovered and listed by the “glimmer list:gems:customwidget” command automatically when needed. So, while software developers are too busy crawling in other frameworks, Glimmer DSL for SWT users and software engineers will be delivering excellent service to their customers at warp speed!

Happy Glimmering!