DEV Community

Cover image for Write Code That Writes Code

Write Code That Writes Code

Mohammad Amin Khakzadan on June 13, 2019

We always write codes with our fingers, we always type on our keyboards, and we work hours and hours to create computer programs. But things we wr...
Collapse
 
val_baca profile image
Valentin Baca • Edited

Compilers, transpilers, macros, metaprogramming are all powerful and can be incredibly useful. I've seen thousands of lines of code reduced to hundreds or even just dozens of lines of code. However, they shouldn't be what one goes to first and can severely impact clarity if not used judiciously. I wouldn't go so far as to say to "always" write programs that write code. Avoid overengineering. Sometimes you do just need the one-off script or program.

Nit pick: "code" is already plural, so the "s" in "codes" is redundant. "Write Code That Writes Code" (Edit: this isn't 100% correct either. See replies)

Collapse
 
jdknox profile image
Jeff

Just to nitpick the nitpick: "code" is technically uncountable, like "water." It can be both plural and singular. 😁

"Codes" can also be used properly, e.g., "She has two codes to crack," or "I have two different machine codes to deal with." So the distinction isn't merely pedantic. 😎

Collapse
 
val_baca profile image
Valentin Baca

You are correct. In referring to computer instructions, "code" is uncountable, not plural.

For others: english.stackexchange.com/question...

Collapse
 
mak12776 profile image
Mohammad Amin Khakzadan

In new programming languages we always have a level of abstraction, we have written programming languages to pave the way for us. And that means some works automated by computers.
For example, in the past that we have no programming language except assembly language, for comparing strings, programmers have to write 5 or 6 lines of code, but now we can compare two strings in python or ruby just by putting some equal signs between them. And that is automating the process of writing codes.
We can have more advanced programming languages, or other approaches that short the way of writing programs. But they not invented, and they are not exist.

Thanks for mentioning mistake.
I do not have enough knowledge of English language, but I can understand programming languages very well. 😃

Collapse
 
davehoran profile image
Dave Horan

Ironically, you mention that it would not be needed much with COBOL. In the early 80s when I was a teen, I used code generators all the time to create basic CRUD file maintenance programs that I would then modify for specific business logic. Since just the pre-modidied code was like 40 printed pages long (days of for matrix) it was crazy to write all that by hand. Manual typing errors alone could add days to debugging. The code generators guarantee some level of code consistency and quality, so you knew any problems introduced were from the additional manual code you added.

This is why I like a lot of the CLI tools for various frameworks that will generate the basic boilerplate for a component, model, etc for your app.

Metaprogramming has been around a long time thanks to 'lazy' (aka smart) developers leveraging DYI mindsets.

Collapse
 
itr13 profile image
Mikael Klages

Though I'm all for code that writes code, it should always be done in a way that is understandable, and preferably compile-time with type+syntax checking if possible.

Personally I've been using c# attributes and python decorators to automate a lot of code for me, and it has been delightful

Collapse
 
lakes_todd profile image
Todd Lakes

I believe that in the future, the computer software environment will be able to independently write the necessary code to create the necessary functions for a person. I am surprised that there is still no such thing. But modern technologies can help me write my research paper on special services. One of these websites is the paperial.com/write-my-research-paper I think this will be useful to many students. Students will be able to improve their skills through similar educational services and this will require a minimum of resources.

Collapse
 
juancarlospaco profile image
Juan Carlos

You are literally describing nim-lang.org

Collapse
 
mak12776 profile image
Mohammad Amin Khakzadan

That has come a part of the way. But that isn't complete and perfect. we can always have something better than what we already have. maybe a program that writes nim languages codes.

Collapse
 
balkac profile image
Kral Balkizar

I'm really frightening about the age, when code really starts to write code.

Collapse
 
mdhesari profile image
Mohammad Fazel

That is so true we need to foresee the future and make thimgs impler by inventing new approaches.

Good job

Collapse
 
triptych profile image
Andrew Wooldridge

Here's a link to their newsletter procjam.com/seeds/issues/3/

Collapse
 
triptych profile image
Andrew Wooldridge

Have you heard of Procjam? ( twitter.com/procjam ) you should take a look at their work and potentially collaborate perhaps?

Collapse
 
mak12776 profile image
Mohammad Amin Khakzadan

very good ideas for being generative, and best place for those who do not have time.

Collapse
 
wiltel492019 profile image
Wiltel492019

I don't understand your logic exactly!!!

Collapse
 
mak12776 profile image
Mohammad Amin Khakzadan • Edited

Have you ever tried to maintain a big and unmaintainable source code?