Pls. discuss & improve: inspiration by ScriptFollows
7 posts
• Page 1 of 1
Pls. discuss & improve: inspiration by ScriptFollows
Something I do not like about my MiServer-code is that length of some lines that needs lots of linewrapping. Thinking about this, I wrote a little tool that enables me to transform lines such a this (and this is a short example, but happens to be my first test-case):
into this (which is larger, but more readable and by far easier to maintain, I hope):
The idea is very simple: we just do an ⍎ with the result of "ScriptFollows" ;-)
Any ideas for improvements? Other comments?
- Code: Select all
⍝ d.Add label'Klasse <i class="fa fa-tag fa-fw"></i>'('class' 'control-label col-lg-3' 'for' 'kls')
⍝ sl←(d.Add div'' '.col-lg-9').Add Select'kls'('Bitte Klasse auswählen' '5.1' '5.2' '5.3' '5.4' '5.5' '5.6',[1.5]'' 5.1 5.2 5.3 5.4 5.5 5.6)
into this (which is larger, but more readable and by far easier to maintain, I hope):
- Code: Select all
d.Add label AttributesFollow
⍝ 'Klasse <i class="fa fa-tag fa-fw"></i>'
⍝ (
⍝ 'class' 'control-label col-lg-3'
⍝ 'for' 'kls'
⍝ )
sl←(d.Add div'' '.col-lg-9').Add Select AttributesFollow
⍝ 'kls'
⍝ (7 2⍴
⍝ 'Bitte Klasse auswählen' ''
⍝ '5.1' 5.1
⍝ '5.2' 5.2
⍝ '5.3' 5.3
⍝ '5.4' 5.4
⍝ '5.5' 5.5
⍝ '5.6' 5.6
⍝ )
The idea is very simple: we just do an ⍎ with the result of "ScriptFollows" ;-)
- Code: Select all
∇ r←AttributesFollow
⍝ treat following commented lines in caller as a collection of attributes
⍝ = ScriptFollows + ⍎ ;-)
r←{∊{'⍝'=⊃⍵:'' ⋄ ' ',dtlb ⍵}¨1↓¨⍵/⍨∧\'⍝'=⊃¨⍵}dtlb¨(1+2⊃⎕LC)↓⎕NR 2⊃⎕SI
r←⍎r
∇
Any ideas for improvements? Other comments?
-
MBaas - Posts: 156
- Joined: Thu Oct 16, 2008 1:17 am
- Location: Gründau / Germany
Re: Pls. discuss & improve: inspiration by ScriptFollows
After sleeping over it, I did a major change:
- Code: Select all
∇ r←DataFollows
-
MBaas - Posts: 156
- Joined: Thu Oct 16, 2008 1:17 am
- Location: Gründau / Germany
Re: Pls. discuss & improve: inspiration by ScriptFollows
Although, like you, a fan of ScriptFollows, I share the common aversion to avoidable ⍎.
Within a general practice of defining a name once only (ie not changing the value of a 'variable') I except the Heraclitean variable ∆ (Mutandum?), reading it only on the line on which it is set, or the next one. Thus
∆←('Bitte Klasse auswählen' '')('5.1' 5.1)('5.2' 5.2)('5.3' 5.3)('5.4' 5.4 )('5.5' 5.5)('5.6' 5.6)
sl←(d.Add div'' '.col-lg-9').Add Select 'kls' (↓⌽↑∆)
Like you, I prefer here a list of pairs to a pair of lists, but avoid the 7 in the code, which must always match the length of the list.
Within a general practice of defining a name once only (ie not changing the value of a 'variable') I except the Heraclitean variable ∆ (Mutandum?), reading it only on the line on which it is set, or the next one. Thus
∆←('Bitte Klasse auswählen' '')('5.1' 5.1)('5.2' 5.2)('5.3' 5.3)('5.4' 5.4 )('5.5' 5.5)('5.6' 5.6)
sl←(d.Add div'' '.col-lg-9').Add Select 'kls' (↓⌽↑∆)
Like you, I prefer here a list of pairs to a pair of lists, but avoid the 7 in the code, which must always match the length of the list.
- sjt
- Posts: 21
- Joined: Fri Nov 05, 2010 6:26 am
Re: Pls. discuss & improve: inspiration by ScriptFollows
Ok, you are right - I picked a bad example. The following case is a bit more obvious ;-)
vs.
I also love short functions which take less than a screenful and with that style they easily grow beyond, but I prefer that anyway, because it is so much easier (and less error-prone) to read and edit...
- Code: Select all
ip←(d1.Add div'' '.col-lg-1').Add _html.input''('id' 'plz' 'name' 'plz' 'placeholder' 'Postleitzahl' 'type' 'text' 'class' 'form-control col-lg-1' 'maxlength' '5' 'value' 63571 'style' 'width: 68px;' 'data-validate' 'required,postcode')
vs.
- Code: Select all
ip←(d1.Add div'' '.col-lg-1').Add _html.input'' DataFollows
⍝ 'id' 'plz'
⍝ 'name' 'plz'
⍝ 'placeholder' 'Postleitzahl'
⍝ 'type' 'text'
⍝ 'class' 'form-control col-lg-1'
⍝ 'maxlength' '5'
⍝ 'value' 63571
⍝ 'style' 'width: 68px;'
⍝ 'data-validate' 'required,postcode'
I also love short functions which take less than a screenful and with that style they easily grow beyond, but I prefer that anyway, because it is so much easier (and less error-prone) to read and edit...
-
MBaas - Posts: 156
- Joined: Thu Oct 16, 2008 1:17 am
- Location: Gründau / Germany
Re: Pls. discuss & improve: inspiration by ScriptFollows
And won't it be nice when we can just code this instead
ip←(d1.Add div'' '.col-lg-1').Add _html.input'' ([or at least something very much like it?
'id' 'plz'
'name' 'plz'
'placeholder' 'Postleitzahl'
'type' 'text'
'class' 'form-control col-lg-1'
'maxlength' '5'
'value' 63571
'style' 'width: 68px;'
'data-validate' 'required,postcode'
])
-
Phil Last - Posts: 628
- Joined: Thu Jun 18, 2009 6:29 pm
- Location: Wessex
Re: Pls. discuss & improve: inspiration by ScriptFollows
The ultimate solution!
BTW: did you take that screenshot with an early 15-beta? ;-)
BTW: did you take that screenshot with an early 15-beta? ;-)
-
MBaas - Posts: 156
- Joined: Thu Oct 16, 2008 1:17 am
- Location: Gründau / Germany
Re: Pls. discuss & improve: inspiration by ScriptFollows
I found another nice use for SF today:
MUCH better than one-liners! ;-)
- Code: Select all
sql←ScriptFollows
⍝ SELECT {many fields}
⍝ FROM {one table}
⍝ JOIN {another table} ON {some fields}
⍝ WHERE {several conditions are met}
⍝ ORDER BY {a field}
r←#.SQL.Do src sql
MUCH better than one-liners! ;-)
-
MBaas - Posts: 156
- Joined: Thu Oct 16, 2008 1:17 am
- Location: Gründau / Germany
7 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 1 guest
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group