[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

https://github.com/aainz/AiJson Can I have some criticism o

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 49
Thread images: 3

File: 23756636729_da080ef892_b.jpg (201KB, 683x1024px) Image search: [Google]
23756636729_da080ef892_b.jpg
201KB, 683x1024px
https://github.com/aainz/AiJson

Can I have some criticism on this JSON library I wrote in C89 it's 90% finished.
>>
Here you go:
It's in C89.
>>
File: 1397348182551.jpg (33KB, 640x480px) Image search: [Google]
1397348182551.jpg
33KB, 640x480px
>>57404428
>>
>>57404470
>>
>>57404470
what do you mean?
>>
Who's this semen demon?
>>
>>57404428

is she cosplaying a dark donald duck?
>>
>>57404789
You asked for a critique, that's my critique.
>>
>>57404858
oh ok
>>
>>57404428
where is the documentation?
>>
>>57404885
It is not 100% finished so I haven't written it yet and I still need to add some API funcs.

Here is a basic example how you can use it:

   AiJson *json = AiJsonCreate();
AiJsonError err = AiJsonParseStr(json,
"{"
" \"Num\": 100.100,"
" \"Greeting\": \"Hello\","
" \"Boolean\": true,"
" \"array\": [1, 2, 3, 4, 5, 6],"
" \"Object\": { \"Hello\": true }"
"}"
);

char *str = AiJsonDump(json, 0);
AiJsonDestroy(json);
>>
>>57404798
https://www.flickr.com/photos/tmizo/23756636729
>>
I have a suggestion:
Use calloc instead of malloc so you save all the memset calls
>>
>>57404906
it still need...*
Funcs like

AiJsonError AiJsonGetObject(AiList *object, char *name);
...
>>
>>57404949
that's a good idea
>>
>>57404975
also
void *JsonMalloc(AiJson *json, size_t size)
{
void *mem = malloc(size);
if(!mem)
return 0;
if(!AiListInsert(json->_private.mallocList, mem))
return 0;
return mem;
}

You should
free(mem)
when the list insertion fails
>>
void SkipWspaces(char **str)
{
ParserSymbol symbol;
while((symbol = ParserLexer(**str)) == S_WHITESPACE)
{
*(*str)++;
}
return;
}


what is the point of the symbol variable here? just omit it
>>
>>57404993
yes I missed that thanks

Would the quality of code be comparable to that of someone who has a degree in CS or is it to amateur?
>>
>>57405016
true it's useless
>>
>>57405030
I would say that the code is pretty decent, only there are literally no comments anywhere. Fix that and its pretty good.
Way above average in either case
>>
>>57405016
I also have a return for some reason I removed it
>>
>>57404882
No, seriously.
> reimplements poor man's std::string
> reimplements poor man's std::list
> manual resources' management
> poor man's OOP
It's 2016 for fuck's sake, what's the excuse for not writing it in C++ and make it easier and safer to use, faster to implement and without visible performance loss?
Even Visual Studio team has rewritten their C standard library implementation in C++ to make it more maintainable and faster. Get it? VS's C standard library is itself implemented in C++.
>>
>>57405108
>hey guys I wrote a JSON parser in C89! is my code good?
>HURRR WHY DONT YOU USE C++ ITS BETTER HURRR MUH OOP
>>
>>57405055
Is it good enough to look for a job as a C developer.
I'm currently 18 and I dropped out of HS when I was 15 so I don't have a lot of options.
>>57405108
Well it's always good to know how to do something. C is still used a lot in embedded stuff and I know my list is very basic I just did it to provide an additional challenge I wouldn't reinvent the wheel all the time. Sorry for my English.
>>
>>57405055
I updated the github with all the changes you suggested. Thank you I had missed out of lot of those problems.
>>
>>57405147
OK, fair enough, but if you stick with C you'll be wasting time on small stuff like this most of the time instead of learning programming on a more abstract level.
Your English is fine, BTW.
>>
>>57405225
I started doing programming with Java so I got fed up with Abstraction then I went full C but now I mostly program in C++ with the STL.
>>
>>57405248
So you've made this project in C just to see how it would feel to be writing in C or there is another reason?
>>
>>57405295
Yeah exactly since not every C++ programmer can write in C (much more inversely of course).
>>
>>57405336
I see.
Then at least I think it would be useful to use const here and there, especially for string parameters of those complicated parsing functions.
Also, you're passing arrays for output to functions without passing their size, it's asking for a buffer overflow.
>>
>>57405426
Well in C you can't use constants as array sizes and it's practice to use #define as for the buffer overflow I don't see where my program would buffer overflow I don't pass sizes because I go character by character and it is a null terminated string.
>>
>>57405426
oh sorry I misread about constants yeah I should use them in the arguments of my functions.
>>
>>57405474
I meant e.g. replace "char *" with "const char *" wherever you're not going to modify the string.
For the latter, for instance in AiJsonDumpObjectArray you pass buff to sprintf. It's a code smell even if you're certain that the hardcoded size will do - I'd use snprintf.
>>
>>57405539
I had misread your answer. I'm really not happy with AiJsonDumpObjectArray and it's probably the worst part of my code so I will probably rewrite it with a more elegant and safe solution.
>>
>>57405559
I would have also written a func which uses snprintf to get the proper size but that function is not very portable.
>>
>>57405559
And, more generally, run the code through some static code checkers if you're not doing it already, they're really helpful in finding potential traps.
Also, once you're done, it may be a nice exercise to reimplement the library in a modern, idiomatic C++ - you'll see how much shorter, safer and more maintainable the code will become. I've done that before and it was a real joy to see code turning from a beast into a beauty.
>>
>>57405624
>reimplement the library in a modern, idiomatic C++
That's actually a great idea. I will do that as my next project.
>>
>>57405667
You could make use of some bleeding-edge stuff like C++17's std::variant instead of naked unions.
>>
>>57405712
I'll look into that thanks
>>
>>57404428
Yet another useless hipster project lol
>>
>>57405966
ok
>>
#define NUM_ESCAPE_SYMBOLS 7

const char escapeSymbols[NUM_ESCAPE_SYMBOLS][2] =
{
{ '"', '"' },
{ '\\', '\\' },
{ 'b', '\b' },
{ 'f', '\f' },
{ 'n', '\n' },
{ 'r', '\r' },
{ 't', '\t' },
};


you could write
const char escapeSymbols[][2]
and get rid of the define
I'm not sure if you can omit array size in C89 though
>>
>>57404428
Good on you, OP. Honestly I wish more people wrote libraries for newer standards/tech that work on older platforms, because really 70% of the shit we do with computers on a daily basis don't require even a thousandth of the horsepower we have available.

Just an example, there's nothing stopping, say, a System 7.5 or Windows 95 machine from running an RSS reader with usable performance. Same goes for anything driven with a backend API, really, and stuff like this JSON library make such projects a lot more feasible.
>>
>>57406316
yes I can do that thanks.
>>57406412
Well I wish sometimes that I was a developer in the 90s because everything was much more simple back then now all the abstraction is horrible even desktop software is written in fucking javascript
>>
I just realized size_t is c89 guess I will remove it
>>
File: 084.png (298KB, 600x512px) Image search: [Google]
084.png
298KB, 600x512px
>>57406455
what?
>>
>>57406470
size_t is c99 so I will replace it with unsigned int
>>
>>57406492
it is actually and replacing with unsigned int is really dumb guess I'm tired
>>
>>57406557
that's right
Thread posts: 49
Thread images: 3


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.