J/HouseStyle: Difference between revisions

no edit summary
m (Removed inappropriate "header" template)
imported>Katsumi
No edit summary
 
Line 33:
:::I agree with much of what you say - particularly that full descriptions/explanations of the code don't belong on the main task page. However I do think that a slight increase in the verbosity and amount of comments will help decrease the perceived impenetrability of "standard" J solutions.
:::Using the [[Zig Zag]] task as an example, I think something like one of the solutions in your excellent explanation on the Talk page would be both intriguing and more likely to encourage further study by non-J users, than the current solutions. i.e.
<syntaxhighlight lang="j">
<lang j>
zigzag=: $ [: /:@; [: <@|.`</. i.
</syntaxhighlight>
</lang>
:::vs.
<syntaxhighlight lang="j">
<lang j>
reorder =: /:@;
antidiags =: <@|.`</.
 
zigzag=: $ [: reorder [: antidiags i.
</syntaxhighlight>
</lang>
:::--[[User:Tikkanz|Tikkanz]] 22:46, 14 October 2009 (UTC)
 
:::The [[Select]] task is perhaps a better example. Compare the current solution:
<syntaxhighlight lang="j">
<lang j>
load 'misc'
select=: ({::~ 'choose a number 0..' 0&".@prompt@, ': ',~ ":@<:@# [ i.@# smoutput@,&":&> ' '&,&.>) :: (select@([ smoutput bind 'please choose a valid number'))
</syntaxhighlight>
</lang>
::: to a slightly more verbose one:
<syntaxhighlight lang="j">
<lang j>
load 'misc'
displayMenu =: i.@# smoutput@,&":&> ' '&,&.>
Line 58:
 
select=: ({::~ _&".@prompt@(makeMsg [ displayMenu)) :: ($:@displayBadNumMsg)
</syntaxhighlight>
</lang>
 
:::As a relatively fluent tacit J user, the first version took a little while to come to grips with if for no other reason than because it was so long. --[[User:Tikkanz|Tikkanz]] 02:02, 16 October 2009 (UTC)
Line 86:
If I'm reusing names from other tasks or the [[j:Essays|J wiki]], I will directly link to them here. Otherwise there will be no lede or introduction.
 
'''Solution''':
'''Solution''':<lang j>name =: a succinct but legible definition NB. Possibly references other defined names,
<pre>
NB. as Tikkanz showed, where each name encapsulates a single,
name =: a succinct but legible definition
NB. but powerful thought. No trivial names.
'''Solution''':<lang j>name =: a succinct but legible definition NB. Possibly references other defined names,
</lang>
NB. as Tikkanz showed, where each name encapsulates a single,
NB. but powerful thought. No trivial names.
</langpre>
 
'''Alternative solution (''style'')''':<lang j>name =: alternative, equivalent solution in a different style
<pre>
NB. For example, explicit as opposed to tacit. ALWAYS lead with the preferred
name =: alternative, equivalent solution in a different style
NB. (usually shortest) solution; alternative solutions are merely showcases.
NB. For example, explicit as opposed to tacit. ALWAYS lead with the preferred
NB. Note also that the exact same name is assigned, indicating all solutions
NB. (usually shortest) solution; alternative solutions are merely showcases.
NB. are identical, and could equally be the referent of the Example section.
NB. Note also that the exact same name is assigned, indicating all solutions
NB. Do not present too many solutions; keep the J entry short and sweet.
NB. are identical, and could equally be the referent of the Example section.
NB. Further solutions can always be linked to.</lang>
NB. Do not present too many solutions; keep the J entry short and sweet.
NB. Further solutions can always be linked to.</lang>
</langpre>
 
'''Example''':
'''Example''': <lang j>name argument NB. Example usages; exercise all the interesting aspects,
<pre>
NB. particularly "free" extensions and generalizations
name argument
NB. which are unavailable in the other languages.</lang>
'''Example''': <lang j>name argument NB. Example usages; exercise all the interesting aspects,
NB. particularly "free" extensions and generalizations
NB. which are unavailable in the other languages.</lang>
</langpre>
 
'''Discussion''': Very brief, high-level overview of how the solution works (e.g. mentions the heart of the solution is a built-in J <code>primitive</code>), with an optional [[Talk:J/HouseStyle#J|embedded link]] to a fuller explanation or exposition on the Talk: page.
Anonymous user