Back to front pageView on Hacker News (opens in a new tab)Ask HN: What is the most beautiful piece of code you've ever read?476 pointsby seisvelas (on Hacker News)7 years agoPreferably an elegant snippet rather than an entire (well engineered) codebase.Comments (380) 116 threadsEarlier commentshazeii7 years ago#Recursive gem in PDP-11 assembler: convert binary value in R0 into ASCII:- CNV10: MOV R0,-(SP) ;Converts binary value CLR R0 ;in R0 to ASCII in buffer 1$: INC R0 ;pointed to R1 SUB #10.,@SP BGE 1$ ADD #72,@SP DEC R0 BEQ 2$ CALL CNV10 2$: MOVB (SP)+,(R1)+ RETURNtotalperspectiv7 years ago#Kind of cheating because Kernighan literally labels it as beautiful. It's Rob Pike's implementation of Ken Thomson's regex matcher.https://www.cs.princeton.edu/courses/archive/spr09/cos333/be...p4bl07 years ago#Gregory Chaitin discusses elegance of programs in his book The limits of mathematics, which is a very good read. I wrote a review almost ten years ago here: https://p4bl0.net/shebang/the-limits-of-mathematics.htmlalex-ant7 years ago#Had a case where I needed to update MySQL column's value if an incoming argument is less/greater than it without using functions or procedures.This returns the greatest value (passed ? or max_value column): ?^((?^max_value)&-(? And for minimum: min_value^((?^min_value)&-(?Load more commentsAll comments shown.Couldn't load more comments. Check your connection and try again.
Ask HN: What is the most beautiful piece of code you've ever read?476 pointsby seisvelas (on Hacker News)7 years ago
hazeii7 years ago#Recursive gem in PDP-11 assembler: convert binary value in R0 into ASCII:- CNV10: MOV R0,-(SP) ;Converts binary value CLR R0 ;in R0 to ASCII in buffer 1$: INC R0 ;pointed to R1 SUB #10.,@SP BGE 1$ ADD #72,@SP DEC R0 BEQ 2$ CALL CNV10 2$: MOVB (SP)+,(R1)+ RETURN
totalperspectiv7 years ago#Kind of cheating because Kernighan literally labels it as beautiful. It's Rob Pike's implementation of Ken Thomson's regex matcher.https://www.cs.princeton.edu/courses/archive/spr09/cos333/be...
p4bl07 years ago#Gregory Chaitin discusses elegance of programs in his book The limits of mathematics, which is a very good read. I wrote a review almost ten years ago here: https://p4bl0.net/shebang/the-limits-of-mathematics.html
alex-ant7 years ago#Had a case where I needed to update MySQL column's value if an incoming argument is less/greater than it without using functions or procedures.This returns the greatest value (passed ? or max_value column): ?^((?^max_value)&-(? And for minimum: min_value^((?^min_value)&-(?
Comments (380) 116 threads
Earlier commentshttps://www.cs.princeton.edu/courses/archive/spr09/cos333/be...
This returns the greatest value (passed ? or max_value column):
All comments shown.
Couldn't load more comments. Check your connection and try again.