HackerTrans
TopNewTrendsCommentsPastAskShowJobs

dsvr

no profile record

Submissions

Parsing JSON in C

vely.dev
2 points·by dsvr·4 jaar geleden·1 comments

[untitled]

1 points·by dsvr·4 jaar geleden·0 comments

[untitled]

1 points·by dsvr·4 jaar geleden·0 comments

[untitled]

1 points·by dsvr·4 jaar geleden·0 comments

C programming framework Vely 13 released

vely.dev
2 points·by dsvr·4 jaar geleden·1 comments

New embedded programming language with C as a host language

vely.dev
95 points·by dsvr·4 jaar geleden·68 comments

Greenest Software Framework for Cloud Development Launches

finance.yahoo.com
2 points·by dsvr·4 jaar geleden·0 comments

comments

dsvr
·3 jaar geleden·discuss
There's a framework for C now at https://vely.dev which may help with C strings safety and memory management, among other things.
dsvr
·4 jaar geleden·discuss
Simpler way to parse JSON in C with Vely framework.

See how to get a JSON request from the web, either from an HTML form (via POST) or JavaScript (application/json) request body.

The example shows parsing JSON in two different ways: traversing the whole document, or extracting the exact fields you need.

The example is a list of cities, within states, within countries.

Disclosure: I am Vely's creator. - Sergio
dsvr
·4 jaar geleden·discuss
Here's an example of how an existing (and maybe the oldest?) language but with "new armor" can significantly lower the carbon footprint:

Writing Green Software - Is Our Code Unfriendly to Environment - https://dev.to/velydev/writing-green-software-is-our-code-un...
dsvr
·4 jaar geleden·discuss
Vely is a framework for C developers.

Improvements in Vely 13/12:

- Bunch of examples, including multitenant SaaS Notes application in only about 300 lines of code.

- Added JSON support.

- Added UTF8 support.

- Added Hash table support.

- Added cache for super fast REGEX pattern matching and replacement.

- Simplified SQL queries for a clean simple interface.

- Source files now have .vely file extension to make it easy to recognize Vely code.

- Building applications now has automatic library inclusion.

- Lots of bug fixes.

See release notes at https://vely.dev/release_notes.html for details.
dsvr
·4 jaar geleden·discuss
I've incorporated it in "In a nutshell" section on the front page. Hope it helps people get what Vely does right away.
dsvr
·4 jaar geleden·discuss
That is a very interesting suggestion. The API underneath is already well-defined and documented in code. Something to consider for sure.
dsvr
·4 jaar geleden·discuss
In this case, just check if there is, near the beginning of file:

#include "vely.h"

which has to be in every Vely .v file.
dsvr
·4 jaar geleden·discuss
That is one of the use cases I would say are perfect for Vely. A combination of a low-level and high-level approach, which is often needed, and not just in this arena.

IOT (Internet Of Things) is a major application area for Vely. Obviously what you mentioned may fall into that. But also for example IOT-edge systems, where the communication with multiple near-devices converges, gets processed and then delivered to a cloud server for congregation.
dsvr
·4 jaar geleden·discuss
Thank you for this feedback. I really appreciate it. I will incorporate it prominently on the web site.
dsvr
·4 jaar geleden·discuss
I guess you could say that. Quite a few comparisons here, and none really wrong as it's all in the eye of a beholder. Vely's main goal is to give you building blocks for general purpose application development, especially including web applications.
dsvr
·4 jaar geleden·discuss
Vely statements are created to generate safe code that will take care of memory issues you mentioned. It's like using a library that does something for you safely, except that Vely provides an interface that is more flexible and easier.

The trick is for Vely to be rich enough to provide the functionality that's typically needed. That is its goal. I hope it's far enough along to be useful, and with time it will get even more so.

Generally, the memory used by Vely statements is created by Vely and you don't have to free it, in fact you shouldn't, it will be freed automatically, even if those pointers are lost or overwritten. The approach is to drastically minimize using C's allocation, and do that only when absolutely necessary, which for most applications should be never.

However, you can still write any C code that does horrible things with memory. Vely exists so you don't have to. The idea is to use Vely to write code that you might otherwise write in pure C and have those issues.
dsvr
·4 jaar geleden·discuss
At the time I didn't know that. Perhaps .vely extension, I guess that would do it. Something to consider to be nice for sure. Thanks for that.
dsvr
·4 jaar geleden·discuss
I didn't know about Vlang, I checked it out, looks very cool.

Vely is really not a language breakthrough. Not at all.

I would say Vely is a practical workhorse. It is about power of rapidly doing business. Kind of like PHP but more in a declarative way like SQL, within C.

As in, you need a collection of libraries that do all the stuff you need to build an application (run queries, build strings really easy, execute programs, do web calls, deamonize programs etc.).

And you need it without writing C code or using API or procuring libraries and header files, but rather you'd just spill your thoughts about what to do in a language that sounds like a natural language, where even the order of how you say it isn't that important.
dsvr
·4 jaar geleden·discuss
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.
dsvr
·4 jaar geleden·discuss
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.
dsvr
·4 jaar geleden·discuss
No, Vely does not understand C. Yes, gcc produces error messages when it comes to C code itself. However, the line number where the issue is located is exactly matched to the Vely source code using #line directive, so I would say 90+% of the time you don't have to look at the generated code. If that is not enough, you can use --c-lines to get the error reported from generated code, which is the exact error, and in that case, yes like you said you need to look at the generated code. Most of the time, however, just looking at the exact embedded statement is enough to figure out what the problem is.

I mentioned in another post that a C program could be parsed to the extent to allow better checking. Not to the point where you'd build a gcc-look-alike, but just enough for instance to know the type of the expression, and if the expression used in Vely statement is correct, and such. Perhaps that's something to consider. I thought about it here and there, but found it to be more useful to check for logical conflicts, such as not providing required arguments, balancing beginning and end of multi-part statement, incorrect usage and such. Typically, using the wrong type accounts for most of the issues, and gcc produces very good messages. Again those messages get matched to the source Vely file exact line number, and I found that correcting an issue isn't difficult.

Your tool sounds great, and if it works what you need it do, awesome! I do things like that all the time, and find that often times using tools is an overkill, and just skip it. There's time and place for everything.
dsvr
·4 jaar geleden·discuss
Ha ha, okay you got me. It's a piece of code that is for demonstration only. But I needed a simple piece of code that speaks of shrinking, without making the front page an exercise in design patterns.
dsvr
·4 jaar geleden·discuss
I changed the indentation of lists to be smaller. At first just for mobile via media CSS, but then it seemed more readable for desktop too. So it should look better now.
dsvr
·4 jaar geleden·discuss
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.
dsvr
·4 jaar geleden·discuss
It is fixed. Thanks again.