Today in hare brained programming ideas— what if we wrote code in Markdown files
-
Today in hare brained programming ideas— what if we wrote code in Markdown files?
Hear me out…
A simple Ruby class (PORO): Foo
w/ methods: bar & bazfoo.rb:
class Foo
def bar
puts “ab”
enddef baz
puts “xy”
end
end———
foo.md:
# Foo
## bar
puts "ab## baz
puts “xy -
Bonus hare brained programming idea— what if we inferred the conventional class name/namespace from its filename/folder?
foo.rb:
def bar
puts “ab”
enddef baz
puts “xy"
enddef whoami
puts class.name
end———
foo.md:
## bar
puts "ab## baz
puts “xy## whoami
puts class.nameBenefits of Markdown as code files:
- docs / code are the same thing
- pretty formatting of comments
- all of the Markdown editors already Just Work
- flatter file / two levels less indentation
- inferred ends/closers from starting the next heading
- directly linkable with href=#___ links
-
Today in hare brained programming ideas— what if we wrote code in Markdown files?
Hear me out…
A simple Ruby class (PORO): Foo
w/ methods: bar & bazfoo.rb:
class Foo
def bar
puts “ab”
enddef baz
puts “xy”
end
end———
foo.md:
# Foo
## bar
puts "ab## baz
puts “xyBonus hare brained programming idea— what if we inferred the conventional class name/namespace from its filename/folder?
foo.rb:
def bar
puts “ab”
enddef baz
puts “xy"
enddef whoami
puts class.name
end———
foo.md:
## bar
puts "ab## baz
puts “xy## whoami
puts class.name -
Tradeoffs of Markdown as code files:
- notice I didn't use code fencing backticks around the Ruby code… that would get noisy
- default would be to treat text between ## h2 headings as code?
- comments have to be… blockquotes? wrapped in --- HRs? or something
- what syntax for code comments? //
Really REALLY hare brained idea—
Multiple programming languages
- in the same file!?
- with file extension? eg, foo.rb.md
- …
-
Benefits of Markdown as code files:
- docs / code are the same thing
- pretty formatting of comments
- all of the Markdown editors already Just Work
- flatter file / two levels less indentation
- inferred ends/closers from starting the next heading
- directly linkable with href=#___ links
Tradeoffs of Markdown as code files:
- notice I didn't use code fencing backticks around the Ruby code… that would get noisy
- default would be to treat text between ## h2 headings as code?
- comments have to be… blockquotes? wrapped in --- HRs? or something
- what syntax for code comments? //
-
Really REALLY hare brained idea—
Multiple programming languages
- in the same file!?
- with file extension? eg, foo.rb.md
- …
@veganstraightedge TextMate was innovative as an editor in its day hecause you could specifically have multiple grammars active in one file.
For instance, you could have a Ruby file with a heredoc string where SQL was used to signify the end of the string and TextMate would syntax highlight that heredoc string as SQL.
-
@veganstraightedge TextMate was innovative as an editor in its day hecause you could specifically have multiple grammars active in one file.
For instance, you could have a Ruby file with a heredoc string where SQL was used to signify the end of the string and TextMate would syntax highlight that heredoc string as SQL.
Vim, technically, can do that too but there’s no built in way to do that, you need a plugin.
Zed supports multiple syntaxes. It even has it built in. For example a <<SQL heretic in Ruby would automatically get SQL syntax (both highlighting and navigation/text objects/selection). And you can specify desired syntax for any supported language.
Similarly, you get both HTML and Ruby in ERB.
-