photopea / UPNG.js

Fast and advanced PNG (APNG) decoder and encoder (lossy / lossless)
MIT License
2.1k stars 259 forks source link

code style #12

Closed fisker closed 6 years ago

fisker commented 6 years ago

the source code is really difficult to read, should we change another code style?

photopea commented 6 years ago

Hi, what style changes do you suggest? Are you sure it would make the code easier to read?

fisker commented 6 years ago

personally i recommend standrand, or just use prettier to format code.

fisker commented 6 years ago

and also i think there is too many private methods on UPNG object. i think just define the function in the closure and use it directly. no need to expose

photopea commented 6 years ago

Do you mean more newlines? The code would be much longer and you will have to scroll more between different parts. It would be harder to get an idea what is going on.

I am used to making every function accessible globally. Actually, I don't use "closures" in my regular code, I just added it here because users asked for it.

fisker commented 6 years ago

if the size of source code is what you worried about, i think we should separate them in to different modules. and use a build tool to compile.

fisker commented 6 years ago

i forked the repo and try to do what i said yesterday. cause there is no test case, i didn't test yet. but you may understand what i want to do.

check this https://github.com/fisker/UPNG.js

tell me what do you think

photopea commented 6 years ago

Hi, I see you have changed the writing style (more newlines, no semicolons etc.) You also added many other files, which I am not familiar with.

I still prefer to maintain this version with my own "writing style". BTW. I have completely remade the quantization process (which makes 30% of the whole library). I will update it here, too, in upcoming weeks.

fisker commented 6 years ago

thank you.

i will keep rewriting the code until i understand how this works.

great job

photopea commented 6 years ago

So what your goal is? What exactly do you want to understand?

fisker commented 6 years ago

no goals, i want understand everything, each function , whole process. but the variable names seems meanless to me.
so i can't understand what the functions doing

photopea commented 6 years ago

I don't think it is a right way to learn about these things from the source code. I recommend you to read the PNG specification and maybe some articles about vector quantization.

BTW. the new quantization algorithm, that I implemented, is 10x faster than this one :) I also think it produces better results.

fisker commented 6 years ago

for example the methods in UPNG._bin , i do't understand the p, l stands for , so i read carefully and change them into meaningful variable names. like this https://github.com/fisker/UPNG.js/commit/f44a0711bfd4d47ac9c98b74b52f05cd86d1a81a

this might take while , but this is what i'm going to do

fisker commented 6 years ago

it's ok, i like reading source code