News for hackers. Stuff that matters.
Re:New embedded programming language with C as a host language by dsvr on Monday July 25, 2022 @05:52PM (#32231418)
Sergio here, the creator of Vely. Go ahead and roast it. Here's a brief from the front page:

Vely is an embedded programming language with C as a host language. It's precompiled into C, creating a native executable.

Vely empowers C with rich features, simplicity and enhanced safety. It is general-purpose and well-suited for web applications.

Use Vely to rapidly develop high-performance and low-footprint applications

Re:New embedded programming language with C as a host language by throwawaymaths on Tuesday July 26, 2022 @12:44AM (#32234329)
I think I like the idea but I have a really hard time figuring out what exactly the code is doing. This is in contrast to say (in my experience), jsx - where what's going on is quite obvious, or zig, where for the most part it's clear what "the equivalent c would be".

I apologize, I don't have specific feedback beyond a vague sense of mild confusion or constructive ideas on how to make it better, hopefully someone else brighter than I can take a crack at it?

Re:New embedded programming language with C as a host language by dsvr on Tuesday July 26, 2022 @01:20AM (#32234554)
Thanks for your feedback. You can see the equivalent C code for any statement pretty easy. For example, if you go to "tutorials", then "tutorial-stock_app", and follow the tutorial instructions, you can always see the generated C code, which would be in:

  /var/lib/vv/bld/stockapp/__stock.o.c
(so here "stock" is the application name and there's "stock.v" file).

For example, when you see this Vely statement in stock.v (which obviously obtains input parameters from either GET or POST request):

  input-param stock_name
this is line 9 in stock.v.

All you need to do is look for:

  #line 9 "stock.v"
in the generated code (which is /var/lib/vv/bld/stock/__stock.o.c), in this case it's:

  char *stock_name = vey_get_input_param (vey_get_config()->ctx.req, "stock_name")
So in this case, it's just one line of C code. In other cases, it may be many lines. For example, Vely statement which apparently runs the INSERT SQL query:

  run-query#add_data@db = "insert into stock (stock_name, stock_price) vaues ('%s', '%s') on duplicate key update stock_price='%s'" : stock_name, stock_price, stock_price
This is on line 12 in stock.v, and you can simply search for

  #line 12 "stock.v"
in /var/lib/vv/bld/stock/__stock.o.c file. In this case, the generated code looks like:

  VV_UNUSED (_column_count_add_data);
  vely_get_config()->ctx.db->ind_current_db=0;
  static void *_sql_prep_add_data_stock_v_649 = NULL;
  _is_input_used_add_data[0]=1;
  _is_input_used_add_data[1]=1;
  _is_input_used_add_data[2]=1;
  add_data = "insert into stock (stock_name, stock_price) values ('%s', '%s') on duplicate key update stock_price='%s'";
  const char *fname_loc_add_data = "stock.v";
  num lnum_add_data = 12;
  vely_location (&fname_loc_add_data, &lnum_add_data, 1);
  vely_make_SQL (&_sql_buf_add_data, 3, add_data , _is_input_used_add_data[0]==1 ?  (stock_name) : NULL , _is_input_used_add_data[1]==1 ?  (stock_price) : NULL , _is_input_used_add_data[2]==1 ?  (stock_price) : NULL );
  if (_qry_executed_add_data == 1) {vely_report_error("Query [add_data] has executed the second time; if you want to execute the same query twice in a row without a loop-query, use different queries with the same query text (or variable) if that is your intention, file [stock.v], line number [12] ");}
  _qry_executed_add_data = 1;
  vely_execute_SQL (_sql_buf_add_data, &_arow_add_data, (const char**)&_err_add_data, (const char**)&_errm_add_data, 0, 1, 0, &_sql_prep_add_data_stock_v_649, _sql_paramcount_add_data, _sql_params_add_data);
  _nrow_add_data=0;
  vely_db_free_result ();
  vely_free (_sql_buf_add_data);
so about 16 ines of code.

This way you can see what actual C code is generated for any Vely code.

And you can also step through this code in gdb by using --c-lines option in vv.

Re:New embedded programming language with C as a host language by throwawaymaths on Tuesday July 26, 2022 @03:46AM (#32235490)
Maybe you should show more bite-sized simpler examples?

There is a lot going on in your big example, and I wouldn't want to have to download and run it first to get a rough mental model of what's happening.

Re:New embedded programming language with C as a host language by dsvr on Tuesday July 26, 2022 @04:27AM (#32235733)
I see your point. That's something to add to the documentation. For now, I guess, here it is. Each Vely statement generates some C code, maybe a one-liner, maybe quite a few. It works kind of like a declarative statement, SQL comes to mind. Some clauses in a Vely statement are input data, others are output. The generated code will take the input and fill in the output.

And Vely generates a request dispatcher, which takes the "req" input parameter, which is really the name of the source Vely file. So if "req=mycode", then the function "void mycode()" will execute and it must always be defined in source file mycode.v. This makes it easy to always find the code, and quickly grasp what application does.

Unlike C Makefile, you don't have to write a Makefile. Whatever .v files you have in your source code directory will be automatically picked up and made into an application.

The generated code can and will change. It tries to do the best job of doing what is instructed to do. So if you say:

  web-call "http://website.com" response resp response-code rc status len post files "file1"="uploadtest", "file23"="fileup4"
then it will generate the C code to effectively POST a form to website.com that sends two local files to that server, and will get you the response code and status back. You can do this by using CURL library, but it will take quite a bit of C coding to do this. And there are many different combinations and things you can do, and the code gets generated to do it quickly and efficiently.

The same goes for exec-program, run-query, send-file, encrypt-data etc etc. All this things you can program yourself in C, but these statements are flexible and will let you quickly and safely do those things. More like "what I want to do" rather than "how I want to do it". Though, like I said, you can examine the generated C code to see exactly how it's done.

The "hello world" tutorial is good for this. And if you do decide to try Vely, I would say try

  https://vely.dev/123_hello_world.html
first, as it can't get any simpler. It's designed to give you an application in minutes. You'll get a command-line executable, and you will be running your own application server that can take input from Apache or Nginx via FastCGI. The example though uses FastCGI command line client so you don't have to do anything beyond what's already included in Vely package.
Re:New embedded programming language with C as a host language by throwawaymaths on Tuesday July 26, 2022 @08:45AM (#32237516)
This description as is should be on the front page.
Re:New embedded programming language with C as a host language by dsvr on Tuesday July 26, 2022 @05:12PM (#32244108)
I've incorporated it in "In a nutshell" section on the front page. Hope it helps people get what Vely does right away.
Re:New embedded programming language with C as a host language by dsvr on Tuesday July 26, 2022 @01:19PM (#32241098)
Thank you for this feedback. I really appreciate it. I will incorporate it prominently on the web site.
Re:New embedded programming language with C as a host language by dsvr on Tuesday July 26, 2022 @01:22AM (#32234565)
Figured out on the fly hackernews markdown. Pretty neat.
Re:New embedded programming language with C as a host language by tsegratis on Monday July 25, 2022 @06:43PM (#32231930)
I like the premise of embedded generating inline c. Kinda like php for c, rather than html

I'm not sure of custom BNF per generating command. I notice they're mostly order independent, which makes it a little easier to learn, but what's the advantage over c syntax? Is it roughly that pointers etc are impossible. Maybe a c-esque syntax would be more learnable

How does the existing syntax compose, i.e. can the user run away with writing tcl-style scripts

If you don't get a lot of feedback, I would guess it is inpart due to custom syntax being an entry barrier to understanding

I don't know, I think html is easy, so people want power with php. On the other hand for an audience that is using c, by the time I'm doing that, does Vely's custom syntax give me more than a set of convenient c library calls... such as https://kristaps.bsd.lv/kcgi/

In any case, I like the apis, and aim, and I think the premise has legs

Re:New embedded programming language with C as a host language by dsvr on Monday July 25, 2022 @08:10PM (#32232665)
I looked at kcgi and it's pretty cool for CGI/FastCGI if you want a-la-carte and then you use separate libraries for everything else.

Vely has FastCGI built in by default (you can start FastCGI server in seconds with vv/vf), and the output statements (such as @ or p-out) do output to the web (i.e. to the Apache or Nginx reverse proxy) by default.

So you could say in terms of functionality, kcgi is built into Vely transparently.

In terms of additional functionality beyond kcgi, Vely offers

- web constructs (getting input parameters from GET/POST, uploading files, sending files to client with send-file, cookie handling, output to web etc.),

- safer and easier string manipulation,

- database access (mariadb, mysql, postgresql, sqlite) with prepared statements and persistent connections,

- regex (match-pattern),

- exec-program for executing programs,

- file operations,

- encryption/encoding/hashing.

I agree there's a learning curve. I can't say how would people see that, though the idea is to be easier than a traditional API, simply on the account of writing a single statement instead of say 5-10 C API calls.

Re:New embedded programming language with C as a host language by dsvr on Monday July 25, 2022 @06:52PM (#32232012)
Thanks for the feedback. The clauses in statements are not order dependent, so they can be specified in any order. No need to remember what goes where, just splatter your thoughts out.

Vely is meant to be more human-readable than APIs; it leans more declarative than API. Each statement typically does what a number of C API calls would do, so the idea is to save time by saying what you need done rather than placing a number of API calls. At the same time, it's safer because it handles all the details and has a memory garbage collector.

For instance, web-call does all kinds of GET and POST calls. run-query does SQL queries. write-string composes complex strings. Etc.

Vely is also a thin framework. You can fire up FastCGI application server in minutes, and use the same program to run a command-line program.

Re:New embedded programming language with C as a host language by tsegratis on Monday July 25, 2022 @06:49PM (#32231993)
Maybe, rather than php, a "reactjs for c" is the direction you're heading
Re:New embedded programming language with C as a host language by dsvr on Monday July 25, 2022 @06:56PM (#32232050)
Interesting thought. Yes, it makes writing applications, easier, it inherits the top performance of C, it's got a lot of rich functionality.

Vely is also a thin framework that mostly helps with building apps by not having to write Makefile, it will pickup any .v files you got.

And it will generate a dispatcher for requests.

But the framework doesn't do much, only the essentials, and that's by design. After all, C is all about flexibility, and that stays.

Re:New embedded programming language with C as a host language by pvg on Monday July 25, 2022 @09:11PM (#32233087)
and roast it

hopefully not although Slor HN could be a variant of Show HN but for roasting.

Re:New embedded programming language with C as a host language by dsvr on Monday July 25, 2022 @09:23PM (#32233174)
I am into grilling and griddling and cooking, so comes natural to me :>
Re:New embedded programming language with C as a host language by taylorius on Tuesday July 26, 2022 @06:05AM (#32236351)
Many new safer-than-C system languages will know what it is to be roasted in the depths of the Slor that day, I can tell you.
Re:New embedded programming language with C as a host language by branko_d on Tuesday July 26, 2022 @02:07AM (#32234874)
> It's precompiled into C, creating a native executable.

This reminds me of Bjarne Stroustrup's original implementation of C++ which was also transpiled to C. That was known as "Cfront" compiler at the time.

Re:New embedded programming language with C as a host language by dsvr on Tuesday July 26, 2022 @04:32AM (#32235762)
Yes, kind of, you're right. C++ though went on for a roller-coaster of complexity, at least that's how I see it.

I think of Vely as staying simple, declarative, and C all the way for performance reasons. More of a collection of practical things you'd want to do.

Re:New embedded programming language with C as a host language by jasfi on Tuesday July 26, 2022 @02:19AM (#32234966)
Nim does the same thing.
Re:New embedded programming language with C as a host language by MaxBarraclough on Tuesday July 26, 2022 @02:29PM (#32242013)
The less celebrated Vala language, too.

https://en.wikipedia.org/wiki/Vala_(programming_language)

Re:New embedded programming language with C as a host language by oefrha on Tuesday July 26, 2022 @01:30AM (#32234628)
Please change

  code {
    font-family: 'DejaVu Sans Mono';
  }
in your CSS to

  code {
    font-family: 'DejaVu Sans Mono', monospace;
  }
For people without DejaVu Sans Mono installed (or for browsers doing a good job at defeating font fingerprinting), which would be most people, the code sample is rendered in the default proportional font, which is very ugly.
Re:New embedded programming language with C as a host language by kazinator on Tuesday July 26, 2022 @01:33AM (#32234645)
How about:

  font-family: monospace;
and that's it.
Re:New embedded programming language with C as a host language by dsvr on Tuesday July 26, 2022 @01:54AM (#32234774)
I found DejaVu Sans Mono to be a bit thinner and easier on the eyes. Either way is fine really. One of those whimsical decisions, I guess.
Re:New embedded programming language with C as a host language by blep_ on Tuesday July 26, 2022 @02:30AM (#32235065)
So change the monospace font in your browser.
Re:New embedded programming language with C as a host language by scoopertrooper on Tuesday July 26, 2022 @10:02AM (#32238401)
Could this not be said about any stylistic choice though? Why should websites pick their own heading weight? What's wrong with the default text colour? Who are you to tell the browser not to use the default padding?

People have been mucking about with typography since Gutenberg's day and they're not going to stop now.

I'm personally 'font blind', but I don't have a problem with people being creative and making aesthetic choices.

Re:New embedded programming language with C as a host language by dusted on Tuesday July 26, 2022 @04:51AM (#32235870)
While I'm totally on board with you on the principle that a website should inform the browser what is, not how to show it, that particular site is hardly the place for this discussion...

_ANY_ article about CSS and client side javascript however.. go go go! :)

Re:New embedded programming language with C as a host language by forgotpwd16 on Tuesday July 26, 2022 @04:37AM (#32235794)
DejaVu Mono is also my preferred monospace font. Have tried some other popular ones but always returned to it.
Re:New embedded programming language with C as a host language by dsvr on Tuesday July 26, 2022 @01:52AM (#32234760)
It is fixed. Thanks again.
Re:New embedded programming language with C as a host language by dsvr on Tuesday July 26, 2022 @01:37AM (#32234661)
Great suggestion, thanks. Will do.