algorithm-archive icon indicating copy to clipboard operation
algorithm-archive copied to clipboard

Wiki - Code style guide

Open PudottaPommin opened this issue 5 years ago • 10 comments

In this thread you can write coding standards, which are accepted in this project. If you add new one, ping me to add it to wiki page.

This is because there are no PR's to wiki possible.

Wiki link

PudottaPommin avatar Oct 07 '18 16:10 PudottaPommin

Python

The coding standart is PEP 8.

Functions and variables should be in snake_case.

Neverik avatar Oct 07 '18 16:10 Neverik

Functions and variables should be in snake_case.

I don't think it's necessary to mention that specific detail, as it's already part of PEP 8.

Butt4cak3 avatar Oct 07 '18 20:10 Butt4cak3

@Butt4cak3 feel free to update that, I don't know how specific the PEP 8 is.

PudottaPommin avatar Oct 07 '18 20:10 PudottaPommin

I think it's worth re-stating the common mistakes we see, because PEP8 itself is huge and complex.

jiegillet avatar Oct 08 '18 03:10 jiegillet

@jiegillet Yeah. We talked about it on Discord and we agreed that we should link to style guides put still explain their most important concepts in our Wiki for reference. I totally agree with you.

Butt4cak3 avatar Oct 08 '18 08:10 Butt4cak3

Yeah, this seems like the most useful way to handle everything.

leios avatar Oct 08 '18 08:10 leios

Scratch

Reference

Before submitting, remember to upload it here. If you don't have an account, you can register one.

Textcode

When submitting, use the Block Plugin format to write your code (or part of it, depending whether to include the interactive part of the code), and store it in algorithm_name.txt.

Indentation

  • The indentation is 4 spaces for every block inside a C-shaped block.
  • Blocks connected to a define block do NOT indent.

Spacing and parentheses

  • Always put a space between an expression (the one that is surrounded by different types of parentheses) and the rest of the block.
  • Always space between // and the rest of the comment, and between the block and //.
  • Do not space between multiple left parentheses or right parentheses.
  • Do not ignore the parentheses at the end of the line.

Literals

  • If an literal is undistinguishable from some other literals (usually empty strings and a string with a couple of spaces), please explicitly mark which it is (using comments).

Separation between sections

  • Always separate different sections of blocks with 1 new line, even if it‘s not necessary.
  • Use 2 new lines to separate between different images to be put on the website.

for example:

define my algo with (arg)
if <(arg) = ( )> // 1 space here
    ...
else
    ...

define a new algo
say [The quick brown fox jumps over a lazy dog]

Svg image

After then, translate the text code into a .svg image using this (or this). and name it algorithm_name.svg.

  • It's recommended to check the image (possibly in a browser) to see if it's well-scaled. If not, you may need to open this file using notepad and change the first occurrence of transform: scale(0.675) to transform: scale(1).
  • You should create 1 image for each part that requires importing.

putting into chapter

  • Put the 2 files mentioned into the corresponding folder. When add to the .md file, follow the format:
{@ sample lang="scratch" @}
<p>
    <img  class="center" src="path/to/svg/image.svg" style="width:40%"/>
</p>

where 40% can be changed depending on the effect you'd like.

  • At the last import, add this line in front of the html label:
The code snippets were taken from this [Scratch project](https://scratch.mit.edu/projects/your-project-id)

where snippets were should be changed into snippet was if there's only this one import.

dovisutu avatar May 30 '20 15:05 dovisutu

(Probably? Maybe some things are missing)

dovisutu avatar May 30 '20 15:05 dovisutu

I think this fits the bill nicely @dovisutu. Thanks!

leios avatar May 30 '20 19:05 leios

I think that since we already have a few Java PRs, we should probably add a style guide, if someone knows of one. In particular, I'm not sure if we should accept PRs that raise exceptions from the main function, as it might teach a potentially bad practice...

So if anyone knows of a style guide, please add it here

Amaras avatar Aug 21 '21 20:08 Amaras