Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

The /prog/matic programmer

Name: Anonymous 2012-09-27 15:16

ANyways, so... I was reading The Pragmatic Programmer [1] and it occurred to me that we should probably boil these principles down for the novices amongst us. ITT things you want to carve into your colleagues' faces.

* KEEP IT FUCKING SIMPLE, MOTHERFUCKER!
* You're code is not ``clever'', it is autistic.
* Code is /not/ poetry or art. Go away! Fuck your OCD.
* This shit has been solved a thousand times over.
* You do not need to design with the latest and greatest in gang-of-four approved OOP design patterns, using infinitely scalable NoSQL solutions in hip new languages that compile down to JavaScript (srsly WTF?!), just to create a CRUD application.
* Not everyone gets off on code, some of us just want to make a living doing the least amount of effort that is required to deliver a consistent quality for an extended period of time.

I swear by god if I see one more AbstractControllerFactoryInterface

[1] http://pragprog.com/the-pragmatic-programmer, easily found online.

Name: Anonymous 2013-05-17 2:00

Well, since you don't like >>30, how about this?


(defpackage #:cudders-secret-box-of-treats
  (:use #:cl)
  (:export #:lines)
  (:shadow car cdr caar cadr cdar cddr))


(in-package #:cudders-secret-box-of-treats)


(defclass promise ()
  ((cached-value :initarg :value)
   (calculator :initarg :calculator)
   (evaluated :initform nil)))


(defmethod force ((self promise))
  (with-slots (cached-value calculator evaluated) self
    (if evaluated
      cached-value
      (progn (setf cached-value (funcall calculator))
             (setf evaluated t)
             cached-value))))

(defun make-promise (calculator)
  (make-instance 'promise :calculator calculator))

(defmacro promise (&rest body)
  `(make-promise (lambda () ,@body)))





(defmethod car ((self list))
  (cl:car self))

(defmethod cdr ((self list))
  (cl:cdr self))

;; need to redefine these so they use the new generic car and cdr.
(defun caar (list)
  (car (car list)))

(defun cadr (list)
  (car (cdr list)))

(defun cdar (list)
  (cdr (car list)))

(defun cddr (list)
  (cdr (cdr list)))



(defclass stream-cons ()
  ((car :initarg :car)
   (cdr :initarg :cdr)))

(defun stream-cons-f (car cdr)
  (make-instance 'stream-cons :car car :cdr cdr))

(defmacro stream-cons (car cdr)
  `(stream-cons-f ,car (promise ,cdr)))

(defmethod car ((self stream-cons))
  (with-slots (car) self
    car))

(defmethod cdr ((self stream-cons))
  (with-slots (cdr) self
    (force cdr)))

(defun stream-append (&rest lists)
  (cond ((null lists) nil)
        ((null (car lists)) (apply #'stream-append (cdr lists)))
        (t (stream-cons (caar lists) (apply #'stream-append (cons (cdar lists) (cdr lists)))))))

(defun for-each (fn list)
  (if (null list)
    nil
    (progn (funcall fn (car list))
           (for-each fn (cdr list)))))


(defun number-lines-stream-list (list)
  (labels ((start-line (line-number list)
             (stream-append (coerce (write-to-string line-number) 'list)
                            (stream-cons #\space
                                         (non-start-line line-number list))))
           (non-start-line (line-number list)
             (cond ((null list) nil)
                   ((eq (car list) #\newline) (stream-cons #\newline (start-line (1+ line-number) (cdr list))))
                   (t (stream-cons (car list) (non-start-line line-number (cdr list)))))))
    (start-line 1 list)))

(defun stream->char-stream-cons (stream)
  (let ((c (read-char stream nil 'eof)))
    (if (eq c 'eof)
      nil
      (stream-cons c (stream->char-stream-cons stream)))))




(defun main (file-name)
  (with-open-file (input file-name)
    (for-each #'write-char (number-lines-stream-list (stream->char-stream-cons input)))))

(main "data.tt")

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List