I am constantly trying to optimize my time. Writing a C code takes a lot of time and requires much more keyboard touches than say writing a Python program.
However, in order to speed up the time required to create a C program, one can automatize many things. I’d like to write my programs using smth. like Python but with C semantics. It means, all keywords are C keywords, but syntax is optimized.
For example, this C code:
#include "dsplib.h"
#include "coeffs.h"
#define MODULENAME "dsplib"
#define NUM_SAMPLES 320
typedef float t_Vec;
typedef struct s_Inter
{
char *pc_Name;
struct s_Inter *px_Next;
}t_Inter;
typedef struct s_DspLibControl
{
t_Vec f_Y;
}t_DspLibControl;
void v_DspLibName(void)
{
printf("Module: %s", MODULENAME); printf("\n");
}
int v_DspLibInitInterControl(t_DspLibControl *px_Con)
{
int y;
px_Con->f_Y = 0.0;
for(int i=0;i<10;i++)
{
y += i * i;
}
return y;
}
in optimized pythonized version can look like:
include dsplib, coeffs
define MODULENAME="dsplib", NUM_SAMPLES=320
typedef float t_Vec
typedef struct s_Inter:
char *pc_Name
struct s_Inter *px_Next
t_Inter
typedef struct s_DspLibControl:
t_Vec f_Y
t_DspLibControl
v_DspLibName():
printf("Module: %s", MODULENAME); printf("\n")
int v_DspLibInitInterControl(t_DspLibControl *px_Con):
int y
px_Con->f_Y = 0.0
for int i=0;i<10;i++:
y += i * i
return y
My question is: Do you know any VIM script, which allows to translate an original pythonized C code into a standard C code? For example, one is writing a C code but uses pythonized syntax, once she decides to translate pythonized blocks into standard C, she selects such blocks and press some key. And she doesn’t save such pythonized code of course, VIM translates it into standard C.
Cython is designed to write python extensions, not full-fledged programs. The same is true for Pyrex.
Even though it’s quite different from your example, PyPy might be what you’re looking for. It uses a Python subset (called RPython, a kind of more statical python) to generate code to different backends – including C. It won’t let you a fine-grained control over data structures as you may want, but give it a try.
What are you asking for is really a different and somewhat easier C dialect – while it might not be a bad idea by itself, there’re already plenty of different programming languages around the world, and it would be quite an issue if everybody invented a new dialect for each app that should be written.
If you think C is too verbose or too lowlevel for your needs, try this approach:
and you’ll probably get great readability, maintainability AND speed.