Re: [Qemu-devel] new to qemu with a simple question
On 05/24/2017 09:30 PM, Eric Blake wrote: On 05/23/2017 09:56 PM, Wang Dong wrote: Hi guys, I am new to qemu. But I need do some job in it right now. When I try read qmp code. I found a interesting part against it. Some C source code is generate from json file. I wonder why this? What is the benefits of this? Boring and repetitive code that is easy to typo is best written by computer, which excels at boring and repetitive tasks. Writing our description in a more concise higher language and generating C code from that lets us focus on the actual design, rather than the mundane correctness of the code implementing the design. It's the same reason that people use bison/yacc rather than hand-written parsers for complex grammars - you isolate the correctness of the code to the correctness of the generator, and free yourself to now only have to worry about the bigger picture of the input you feed to the generator. And on another level, it's why we write programs in C instead of assembly. Abstraction is good. Thanks for your reply. I really appreciate it. -- Best regards. Wang Dong
Re: [Qemu-devel] new to qemu with a simple question
On 05/23/2017 09:56 PM, Wang Dong wrote: > > Hi guys, > > I am new to qemu. But I need do some job in it right now. > > When I try read qmp code. I found a interesting part against it. > > Some C source code is generate from json file. > > I wonder why this? What is the benefits of this? Boring and repetitive code that is easy to typo is best written by a computer, which excels at boring and repetitive tasks. Writing our description in a more concise higher language and generating C code from that lets us focus on the actual design, rather than the mundane correctness of the code implementing the design. It's the same reason that people use bison/yacc rather than hand-written parsers for complex grammars - you isolate the correctness of the code to the correctness of the generator, and free yourself to now only have to worry about the bigger picture of the input you feed to the generator. And on another level, it's why we write programs in C instead of assembly. Abstraction is good. -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org signature.asc Description: OpenPGP digital signature
Re: [Qemu-devel] new to qemu with a simple question
Thank you, Fam. On 05/24/2017 11:11 AM, Fam Zheng wrote: On Wed, 05/24 10:56, Wang Dong wrote: Some C source code is generate from json file. I wonder why this? What is the benefits of this? This allows you to concentrate on the high level semantics of the QMP API, without worrying about C syntax and structural code here and there. In one word, more conciseness and little code duplication. If done in C, it would be much more lines of code and hardly readable. Fam -- Best regards. Wang Dong
Re: [Qemu-devel] new to qemu with a simple question
On Wed, 05/24 10:56, Wang Dong wrote: > Some C source code is generate from json file. > > I wonder why this? What is the benefits of this? This allows you to concentrate on the high level semantics of the QMP API, without worrying about C syntax and structural code here and there. In one word, more conciseness and little code duplication. If done in C, it would be much more lines of code and hardly readable. Fam
[Qemu-devel] new to qemu with a simple question
Hi guys, I am new to qemu. But I need do some job in it right now. When I try read qmp code. I found a interesting part against it. Some C source code is generate from json file. I wonder why this? What is the benefits of this? Thanks in advance. -- Best regards. Wang Dong