Showing posts with label Tony Junkes. Show all posts
Showing posts with label Tony Junkes. Show all posts

Thursday, 18 August 2016

Breaking: Groovy and Clojure answers for that array-look-up code puzzle

G'day:
Well it's not really that breaking really... what I mean is a coupla other people posted some answers to last week's code puzzle after I wrote up the results ("Looking at the code from that code puzzle last week"). I was gonna just append them to the bottom of that earlier article, but hen no-one would see them, and that seemed a bit disrespectful. Also for this blog which is still mostly read by CFML devs, it's some exposure to other languages you might want to take the time to look at, and these are good examples why.

Sean

I was wondering what happened to Sean's Clojure example, but he was off leading his life instead of clearing away the cobwebs from my blog, so didn't notice the code puzzle initially. But here's his Clojure code (fully annotated for us non-Clojurians):

;; simplest solution to find first match -- note that `filter` returns
;; a lazy chunked sequence so it will not search the entire vector
;; however, the chunks are 32 elements in size so it will search up
;; to 31 elements beyond the first match
(first (filter #(re-find #".+at" %) ["at" "cat" "scat" "scratch"]))

;; Clojure has `some` but it returns the result of applying the predicate
;; not the original element so we need to write a "smarter" predicate:

;; will not work in all cases:
(some #(re-find #".+at" %) ["at" "cat" "scat" "scratch"])
;; this: (some #(re-find #".+at" %) ["scratch" "at" "cat" "scat"])
;; produces this: "scrat" -- oops!

;; will work with extended predicate:
(some #(when (re-find #".+at" %) %) ["at" "cat" "scat" "scratch"])

;; or we can use reduce with an early return -- the `reduced` value:
(reduce (fn [_ s] (when (re-find #".+at" s) (reduced s))) nil ["at" "cat" "scat" "scratch"])

;; a note about notation: #(.. % ..) is shorthand for (fn [x] (.. x ..))
;; i.e., an anonymous function with one argument

That looks like a bunch of code, but it's also four examples:

(first (filter #(re-find #".+at" %) ["at" "cat" "scat" "scratch"]))

(some #(re-find #".+at" %) ["at" "cat" "scat" "scratch"])

(some #(when (re-find #".+at" %) %) ["at" "cat" "scat" "scratch"])

(reduce (fn [_ s] (when (re-find #".+at" s) (reduced s))) nil ["at" "cat" "scat" "scratch"])


Now I've only had the most superficial look at Clojure, but even I can just read what's going on in that code. So that's cool. I've been off my game recently with my out-of-hours tech stuff - in case you hadn't noticed - and I really want to finish finding my motivation to get back to it, and look at more Clojure. I think it's a good thing to look at for a perennial CFMLer or PHPer as its quite the paradigm shift, but still seems pretty easy to get at least a superficial handle on, and then work from there.

Tony

Tony's done a Groovy example. Every time I see Groovy, it just seems cool. Check this out:

print( ['a', 'at', 'cat', 'scat', 'catch'].find { it ==~ '.+at' } )

That's it. Done. 67 characters, most of it data. 25 characters of actually "doing stuff", including more whitespace than I'd usually use for this sort of thing. Doesn't that make you want to use Groovy?

Anyway, that's that. I just wanted to share that code with y'all.

Righto.

--
Adam

Saturday, 26 October 2013

CFSummit: interesting ColdFusion 2016 stuff

G'day:
Not that I was at CFSummit, but thanks to Tony Junkes, I saw some interesting slides about ColdFusion "2016" (yeah, the next version, not 11) which can only lead one to speculate...

But first a gripe (hey, this is me, remember). Dazzle? Are you trying to make a mockery of ColdFusion, Adobe? This is like some programming newbie who gives themselves the handle "ProgrammingNinja!" or something. It's not up to you to decide how cool you are; it's up to the audience around you. Rethink that bloody name to something less self-aggrandising. And less like something out of TAoPQotD.

Anyway, the interesting stuff...

Road Map

(yeah, sorry, the links are gonna be links to the photos of the slides that Tony took sorry).

Here we have (time to get my table-based layout skill ready):


Future of the web - verticalAreas
MobileEnterprise Mobility
Responsive Multi Screen Content
Modernized PlatformHigh Performance Runtime
Modular Nimble Engine
Enterprise Class Package Manager
Language Revamp
Horizontals
PeformanceSecurityHTML5


OK, so I'm going to ignore the mobile stuff as it'll still be as wrong to be doing it in ColdFusion 2016 as it is in ColdFusion 11, so I simply don't care.

Modular nimble engine

But "modular nimble engine" sounds interesting. Well forget "nimble": that's marketing-speak. But very pleased they're modularising things. But I wonder to what extent? This conversation has done the rounds a lot of times, and I've posted my own take on it as well: "Survey Results: ColdFusion Modularisation". It can only be a good thing though. ColdFusion has become such a cruft-filled monster that it's time it shook some stuff out of the core. I'm all for leaving stuff like <cfform> and <cfclient> as deprecated options, but they should not be part of the core install. People can install them if they want them using the...

Enterprise class package manager

Here's Tony's photo of the slide (I'll spare you my design skills this time). Cool! Hopefully this is like Ruby Gems or Node.js's NPM system (not that I've used the later... I've not touched node.js, but I've heard great stuff about NPM). It's high time for this, and something people have been clamouring for. It seems to have all the key points:
  • A portal/registry to list all packages available
  • an organization (excuse my ghastly American spelling... I'm quoting this) - a custom package registry
  • CF Developers - easily contribute to this registry
  • info about package exposed as a REST webservice
  • Configure multiple registry URLs
That sounds... perfect. I guess the "Organization" bit is like a sub-registry. So Adobe will maintain an official one, but people can also maintain their own ones? Say for example Ortus want to have BoxManagerBox or something for all their... boxes. Seems reasonable.

Language revamp

(Tony's first photo; second photo; third photo).This is a monster. Check out all the bullet points:

  • Focus on optimized performance on JVM
  • Breaking backwards compatibility
  • Anything with quotes is a string, scope search
  • Increased support for OOP - retain simplicity
  • Tighten interface implementation
  • Collection datatypes
  • New logging framework
  • Create WAR and deploy anywhere
  • Image manipulation revamp
  • Extending the language
  • Concurrency
    • Existing support - CFTHREAD and CFLOCK
    • Synchronized functions and blocks
    • Concurrent data structures
    • Atomic variables and non blocking IO
    • Inherently concurrent - Actor model
What a mountain of stuff!