#code_review

posts tagged #code_review

0

[C] Having a runtime error with a simple function

preview

Hello, I am new to this community, as well as to coding in general. I am having fun learning C, and I’ve generally been able to work through/slam my head into problems until they make sense, but I am confounded by this discrepancy, and I am hoping to have some help with it:

printf("%%c);

Output: %c


#include 

void textGreen(const char* text)
{
    printf("\033[32m%s\033[0m", text);
}

int main()
{
    textGreen("%%c\n");
    return 0;
}

Output: %%c.

Since printf is wrapped into the function, should the text not be outputting with the same behavior? Why is my terminal printing this code without escaping the percent sign? FWIW, the text is green, at the very least.

I am using Ubuntu 23.10, the code was written in KATE, it was compiled in GCC, and it was run on the basic GNOME terminal.

Hello, I am new to this community, as well as to coding in general. I am having fun learning C, and I’ve generally been able to work through/slam my head into problems until they make sense, but I am confounded by this discrepancy, and I am hoping to have some help with it:

printf("%%c);

Output: %c


#include 

void textGreen(const char* text)
{
    printf("\033[32m%s\033[0m", text);
}

int main()
{
    textGreen("%%c\n");
    return 0;
}

Output: %%c.

Since printf is wrapped into the function, should the text not be outputting with the same behavior? Why is my terminal printing this code without escaping the percent sign? FWIW, the text is green, at the very least.

I am using Ubuntu 23.10, the code was written in KATE, it was compiled in GCC, and it was run on the basic GNOME terminal.

0

[Rust] Simple predictive text review

GitLab code review: review this (3a1cf8ed) · Commits · NamingThingsIsHard / linux / Chordnix · GitLab gitlab.com
preview

I wrote a simple algorithm for predictive text that uses preceding words as context. Without looking at prior, it was an attempt as seeing what I could come up with.

The goal is for it to be incorporated in chorded input and pick the best candidate for the entered chord with the given context. Chorded input is the method of hitting all keys for a word simultaneously instead of hitting each key individually in expected order.

E.g you’ve typed “this is the worst” and hit the chord “aet”, which word should be chosen? ate? tea? eta? This algorithm is there to answer that.

What I’m looking for in the code review in order of importance:

  • documentation (is it understandable? are there things missing? …)
  • code architecture, code structure (function should be a member? composition could be changed? clarity, …)
  • algorithm review (optimisations, improvements)
  • variable and class names (naming things is hard)
  • rust specific stuff (f64 instead of u32 maybe? dyn vs impl? …)

The code is linted and automatically formatted.

I wrote a simple algorithm for predictive text that uses preceding words as context. Without looking at prior, it was an attempt as seeing what I could come up with.

The goal is for it to be incorporated in chorded input and pick the best candidate for the entered chord with the given context. Chorded input is the method of hitting all keys for a word simultaneously instead of hitting each key individually in expected order.

E.g you’ve typed “this is the worst” and hit the chord “aet”, which word should be chosen? ate? tea? eta? This algorithm is there to answer that.

What I’m looking for in the code review in order of importance:

  • documentation (is it understandable? are there things missing? …)
  • code architecture, code structure (function should be a member? composition could be changed? clarity, …)
  • algorithm review (optimisations, improvements)
  • variable and class names (naming things is hard)
  • rust specific stuff (f64 instead of u32 maybe? dyn vs impl? …)

The code is linted and automatically formatted.

0

[Rust + Tauri + React] Cryptography Usage Review

GitLab src-tauri/src/app/crypto.rs · master · treedome / treedome · GitLab gitlab.com
preview

I’m making an offline first, note taking application made with rust+tauri. I’ve reviewed this before with one of my friend and he checks everything from the way I use the library, how I uses my nonces, salt, and the like. But It’s never a bad thing to ask you guys for some thought, if any.

Please take it slow, assume the best, and be gentle with me.

I’m making an offline first, note taking application made with rust+tauri. I’ve reviewed this before with one of my friend and he checks everything from the way I use the library, how I uses my nonces, salt, and the like. But It’s never a bad thing to ask you guys for some thought, if any.

Please take it slow, assume the best, and be gentle with me.

0

Tips on making code reviewable on source forges

preview

Source forges like Gitlab, Gitea, Forgjo, Github, and others do not allow directly leaving comments on code. However, they all do allow leaving comments on pull/merge requests and individual commits. This unfortunately doesn’t work for snippets like Gitlab Snippets, Github Gists, etc. .

We can however use these to our advantage and use workarounds in order to make certain parts of our code reviewable:

Snippets

Create a repository to host your snippets (if you don’t have one already), add your snippet of code as one commit to the repository (can be in a throwaway branch, the master branch, whatever). Share that commit link!

Larger changes

If you have code that belongs together, it is already in your repository, and is spread out over multiple commits, fear not! Once again, you can use the power of temporary branches. With these methods you can even have your entire repo reviewed.

A commit to review

Create a new branch, delete the parts of the code you want reviewed, create a revert commit, and share that link!

A PR to review

This requires 2 branches. If you’ve read the steps above, you already know where this is going.

Create a branch (deleted), delete the code and commit it. Create a new branch (revert) from this point and revert the previous commit. Now you can push both branches to your source forge and create a new merge request to merge revert into deleted.


If you have other tips, share them!

Source forges like Gitlab, Gitea, Forgjo, Github, and others do not allow directly leaving comments on code. However, they all do allow leaving comments on pull/merge requests and individual commits. This unfortunately doesn’t work for snippets like Gitlab Snippets, Github Gists, etc. .

We can however use these to our advantage and use workarounds in order to make certain parts of our code reviewable:

Snippets

Create a repository to host your snippets (if you don’t have one already), add your snippet of code as one commit to the repository (can be in a throwaway branch, the master branch, whatever). Share that commit link!

Larger changes

If you have code that belongs together, it is already in your repository, and is spread out over multiple commits, fear not! Once again, you can use the power of temporary branches. With these methods you can even have your entire repo reviewed.

A commit to review

Create a new branch, delete the parts of the code you want reviewed, create a revert commit, and share that link!

A PR to review

This requires 2 branches. If you’ve read the steps above, you already know where this is going.

Create a branch (deleted), delete the code and commit it. Create a new branch (revert) from this point and revert the previous commit. Now you can push both branches to your source forge and create a new merge request to merge revert into deleted.


If you have other tips, share them!