Re:The SQL Trap
by mahmud on Monday June 22, 2009 @10:28PM
(#669755)
Parsing?
I don't think that's the point of using basic serialization; it's not that you need to write-out and parse-in your data structures manually, it's because your language already provides the means to serialize all the datastructure you use, without having to bolt a relational model on to it.
For example, Lisp provides the PRINT-OBJECT method which you can specialize to "print" CLOS objects anyway you like; I use a tiny transactional object store to READ and WRITE the data structures into disk without worry (rucksack, which kicks butt btw) however, to display them, I specialized PRINT-OBJECT method for various views:
; print as html table
print-object ((object user-data) (stream http-stream))
; print as CSV
print-object ((object user-data) (stream csv-stream))
; display on the console, for interactive use
(defmethod print-object ((object user-data) stream)
(with-slots (id name email last-login) object
(format stream "~a ~a ~a ~a~%"
id name email last-login)))
The result is that I can do (print (make-instance 'user-data)) and it would print on one line, if I am interacting with it; or it would print as an html table, if I refresh my browser and the printing code is invoked by the page handler; or it would print as semi-colon separated CSV values if I am printin out to a file.
The parser and reader are already provided by the language, you just tweak them when you want to fit your aesthetics without loss of functionality.
I don't think that's the point of using basic serialization; it's not that you need to write-out and parse-in your data structures manually, it's because your language already provides the means to serialize all the datastructure you use, without having to bolt a relational model on to it.
For example, Lisp provides the PRINT-OBJECT method which you can specialize to "print" CLOS objects anyway you like; I use a tiny transactional object store to READ and WRITE the data structures into disk without worry (rucksack, which kicks butt btw) however, to display them, I specialized PRINT-OBJECT method for various views:
The result is that I can do (print (make-instance 'user-data)) and it would print on one line, if I am interacting with it; or it would print as an html table, if I refresh my browser and the printing code is invoked by the page handler; or it would print as semi-colon separated CSV values if I am printin out to a file.The parser and reader are already provided by the language, you just tweak them when you want to fit your aesthetics without loss of functionality.