Hacker News new | ask | show | jobs
by ivansavz 3302 days ago
Yes .tex programming is probably the least intuitive kind of language I've ever seen. Here is a FizzBuzz in vanilla .tex for anyone who curious to see what that's like:

    % fizzbuzz.tex -- Compile with pdftex, not pdflatex
    \def\modulo#1#2{(#1-(#1/#2)*#2)}	% a mod n = a-(a/n)*n   where / is integer division

    \newcount\X
    \X=1
    \loop
    	\ifnum \numexpr\modulo{\X}{15} = 0
    		FizzBuzz
    	\else
    		\ifnum \numexpr\modulo{\X}{3} = 0
    			Fizz
    		\else
    			\ifnum \numexpr\modulo{\X}{5} = 0
    				Buzz
    			\else
    				\the\X
    			\fi
    		\fi
    	\fi
    	\endgraf
    	\advance \X by 1
    	\unless \ifnum \X>100
    	\repeat
    \bye
2 comments

That's pdfTeX, not vanilla TeX.

    $ tex
    This is TeX, Version 3.14159265 (TeX Live 2016/Debian) (preloaded format=tex)
    **\show\numexpr
    > \numexpr=undefined.
Honestly, that doesn't seem that non-intuitive to me. Certainly missing opening and closing brackets, but if closing with fi is a common idiom of old languages. The rest doesn't seem that bad. Just verbose.
I had never seen this kind of yoda-speak before:

    \unless \ifnum \X>100 \repeat
I guess to me it doesn't read that much worse than "if (!(x < 100))", which is somewhat bad form, but not unreadable. (More likely would it have been "if (!aboveThreshold(x))". I know I have seen similar in some lisp code. At least, I have seen "unless" before.

Don't take my comment as my rushing out to embrace TeX. I just don't think it is nearly as bad as its reputation.