From: 7stud -- Date: 2011-03-15T11:42:20+09:00 Subject: Re: Understanding YAML and this practice in general Fily Salas wrote in post #987440: > I started > wondering when and why you would need to save the output of a program? > > Sorry if my question doesn't make too much sense but I'm coming from a > web development world with only some knowledge in Actionscript 3.0, > Javascript, CSS and HTML. Have you ever heard of a logfile? The idea is that something monitors a program you are running and logs information to a file about various things that occur while the program is running. You can then open the file and read the file to see what happened while your programming was running. With a unix program like tail, you can even open the file and watch the changes to the file in real time. Do you know what a cookie is? It is a file on a user's computer that contains a short bit of information. Sometimes a javascript program writes output in the form of a cookie. Suppose you run a business, and at the end of every day your employee enters information about every transaction in a file. The information contains the customer's name and the dollar amount purchased--one line in the file for every transaction. You ask your ruby programmer to write a program that reads all the transaction files and print out the total amount each customer spent that month. The program must read each transaction and record all the transactions for each customer, i.e. one customer could have 100 separate transactions spread through out the files. The ruby programmer could output the totals to another file, arrange them alphabetically by customer name, and then send the file to you my email. Video games store totals and high scores to files. TV's store favorite channels and programs to be recorded in files. It would be easier to try and count the programs that don't store output to files...in fact I can't think of a single one. > I know its probably too early to ask this kind of questions but I really > started wondering since he started talking about YAML which apparently > can be used in multiple languages and I'm assuming this is an important > part of programming? > > Can someone be so kind and explain me when and why you would need YAML? > At the heart of your question is the question of data persistence--in other words how can you make data persist from one program run to the other. Anyone can make a string persist by writing a string to a file and reading it back later, but what about arrays and even objects(=things that store both data and functions/methods. How can you store those in a file and then read them back later? YAML and the many other programs that "serialize" data allow you to easily store things like arrays, hashes/dictionaries, and objects to a file and then reconstitute them the next time you run a program. YAML's claim to fame is that the file it creates is human readable. In the beginning, data serializers stored what looked like random characters in a file. They were actually complex codes, that a computer could decipher. -- Posted via http://www.ruby-forum.com/.