[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vip /vp / vr / w / wg / wsg / wsr / x / y ] [Search | Home]
4Archive logo
Rate my coding style. Should I have brackets...
If images are not shown try to refresh the page. If you like this website, please disable any AdBlock software!

You are currently reading a thread in /g/ - Technology

Thread replies: 85
Thread images: 6
Rate my coding style. Should I have brackets on new line or after closing round brackets?
>>
You have all the code inside main.
You have comments repeating what the code says just fine.
You repeat the argc > 1 check.
No one cares about what you want, you should describe details which can't be expressed with code.

TL.DR Read "Clean Code"
>>
why would you name your variable fd
>>
This is better no?
>>
What is this "return 0"?
>>
K&r style brackets or gtfo
>>
>>52481093
In the main function, returning another number besides 0 ends the program with an error code.
>>
>>52480593
Pray to god that Linus never sees your code in any official capacity.
>>
>>52481044
Shouldn't you malloc on ifr.ifr_name to be able to copy that string?
>>
>>52481250
Why would a YouTube hardware reviewer look at anyone's code?
>>
It's the GNU style.
>>
>>52481093
Why wouldn't you put that?
>>
>>52481313
Please tell me you were trolling.
>>
>>52481382
Does Linus have another YouTube channel I'm not aware of?
>>
>>52481393
He was referring to Torvalds. You know, the Linux kernel creator and Linux foundation CEO.
>>
>>52481187
but why do you explicitly return 0 and telling the system that program is ok? what if it indeed has errors? Isn't the compiler's job to do this and not programmer's?
>>
>>52481809
Runtime errors have to be made by programmers. All the errors you see in any program are specifically encoded by programmers.
>>
>>52481859
Are they predicting errors or they are actually making errors to appear in runtime? For what purpose?
>>
>>52480593

after

why devote a whole line to just a bracket
>>
>>52481931
because it makes it easier to read
>>
>>52481945
>implying
>>
>>52480593
It's okay but if you want to learn professional C you should look at the OpenBSD source code or of their programs.

http://cvsweb.openbsd.org/cgi-bin/cvsweb/src/bin/

Chromium and other Google products are also nice to learn good coding.
>>
>>52480593

Why not just use a scripting language for this mate?
>>
>>52481895
>>52481809
>These are the people you post on /g/ with
>>
>>52481895
Errors are thrown when a condition is met. For example, if you wanted to throw an error when a value went below zero, such as xp in a video game:

if(currentXP() < 0)
throw XPOutOfBoundsException;


The error will pass up through the hierarchy of the program until it reaches a try{} block, or it will exit the program and pass the error into the operating system.

The XPOutOfBoundsException was a class created by the programmer in another part of the code.
>>
>>52482018
That anon just honesty asked the question,do you prefer more mobile phone/desktop/headphone/windows/mac people with their threads?
>>
>>52481093
>>52481809

Some languages use functions and subroutines, most don't. A function that returns 0 is essentially the same as a subroutine. It is a very, very common thing.
>>
>>52481995
Found a bug in http://cvsweb.openbsd.org/cgi-bin/cvsweb/~checkout~/src/bin/sh/Attic/eval.c?rev=1.6&content-type=text/plain&only_with_tag=MAIN
Line 113, skipcount not being reset.
>>
i will never understand why people still use shit like VIM in 2016
>>
>>52482116
I will never understand why people still use shit like Windows in 2016.
>>
>>52482116
What do you prefer? But then again it depends on the language what editor or IDE to use.
>>
>>52480593
>using C
pleb/10, try using a real language next time
>>
>>52482116

I know some people will say NEVER USE AN IDE but I think a less extreme way to put it would be to never use an IDE unless it's necessary.

To hack out some code that has no need to be in an IDE why would I ever even open an IDE? What a pain in the ass.

I'm the same way with my operating systems. I am not a zealot, I use Windows, OSX, and Linux however the situation dictates which most of my everyday computing being on Linux.

If you feel an IDE is necessary for something then go for it, if not then why not use VIM/a text editor?
>>
>>52482132
any text editor that allow me to use the mouse
>>
>>52482176

Oh, well then disregard >>52482170 since you do use a text editor.

But, I use VIM and have it set to allow me to use a mouse if I want to, just so you know.
>>
File: Code-C_001.png (57 KB, 783x505) Image search: [iqdb] [SauceNao] [Google]
Code-C_001.png
57 KB, 783x505
rate my coding style
>>
>>52482170
I never said IDEs are better, but still I cant like VI/VIM, the efford to learn is is just to code is ridiculous, I just use any other text editor like Kate, Gedit, Notepad++, damn, even Nano if I need to edit something really fast in terminal.

Using Vim in something like a project in Ruby on Rails should be shit, when you need to move between files many times
>>
>>52482199
But how can you use such editor that has no autocompletion? For example imagine doing html,css,javascript,c++ in VIM. You need to write everything by hand without autocomplete...
>>
>>52482205
perfect
>>
>>52482251

Vim can do tab completion if you want it to.
>>
>>52481755
Linux is a company?
>>
>>52482600
some goy registered it and tried to sue companies so now linus owns it so that doesn't happen again
>>
>>52482205
>creating a new line for opening bracket

Can't stand that shit.
>>
>>52482205
>8 space tabs
>>
>>52483358
I used to do 4 but I saw the linux kernel did 8 and I'm interesting in contributing to that when I got good so I thought i'd get used to it
>>
>>52483377
i am experiencing the same thing but contributing to atom so i'm doing 2 spaces lol
>>
>>52483377
That's literally only useful for kernel programming where you're probably not going to be nesting very deeply.
>>
>>52481344
Thought I recognised it.
>>
>>52482095
>attic
its old as fuck and unused
>>
>>52481187
Why?

Who designed this language and how autistic were they?

Why not just "return"? Why wouldn't you design your language to parse a function that lacks an assignment to automatically read 0?
>>
File: code.png (22 KB, 907x350) Image search: [iqdb] [SauceNao] [Google]
code.png
22 KB, 907x350
r8 my style.

designed and written so that I can read a ~100 lines a minute.

Also the code is purposefully written to avoid OOP because fuck OOP and everything about it. Arrays 4 lyfe.
>>
>>52484068
>meme comments
>>
>>52484235
I have memes in my comments?

I know they are snarky, but that's just a reflection of my personality to be honest, fampai.
>>
>>52484068
>micromanaging arrays

Nice pet project. Real Men uses structs and classes
>>
>>52484068
I don't see how are you notifying UI layer the player level was incremented.
Example:
UIEvents.pushEvent(Event.playerLevelIncreased(player.level));
>>
>>52482205
beautiful
>>
>>52480593
>opening bracket on new line

just kill yourself to be honest family
>>
>>52485883
Not only that but a semi-indented new line.
>>
>>52483331
>not liking easily distinguishable scope blocks
>>
File: problem_15.png (71 KB, 1439x745) Image search: [iqdb] [SauceNao] [Google]
problem_15.png
71 KB, 1439x745
Came across this beauty earlier today while browsing people's solutions to Project Euler problem 15.
>>
>>52482169
i rate this post b8/10
>>
>>52482169
Javascript, you mean?
>>
>>52480593
it doesn't matter
>>
>>52480593
WTF? you use mcedit for coding?
>>
>>52485998
What were they trying to solve?
>>
bait or bad. Your choice
>>
>>52486371
Given a grid that 20*20 and starting at the top left of the grid how many ways are there to reach the bottom left of the grid if you can only move down and right.
>>
>>52486452
Fantastic
>>
>>52486371
Given a 20x20 grid, how many ways are there to travel from the upper left corner to the lower right? You can only move down or right.

This person's solution is brute force, but inefficient, sort of like the inefficient recursive Fibonacci algorithm. There are ways to solve it faster, such as dynamic programming or building up solutions. It's also possible to write down the answer using some combinatorial tricks.

https://projecteuler.net/problem=15
>>
>>52486506
If you use a language with big number support it's as easy as 40!/20!**2
>>
>>52480593
No point in such a thread since everyone is going to have a different opinion of what's good.
Personally I don't like it. Too many spaces everywhere and why do brackets get their own indentation?
I use K&R with hard tabs, set to 8 spaces per tab.
>>
>>52486452
>>52486506
Would that just be the number of unique permutations?

so, 40!/(20!^2) = 137,846,528,820

I've never used Project Euler. Is there a way to look up answer to see if I'm right?
>>
>>52486674
A google result showed that was correct, but there exists a smarter algorithm based on Combinatorics like >>52486506 said.

Pretty cool
>>
>>52486730
>based on Combinatorics
40!/20!**2 is combinatorics
>>
this fuckin thread.

ctrl+f "strncpy" - no results

>>52480593
Op, you're using strncpy() wrong. I can't see anything above "char *myarg1 = argv[2]" but it doesn't seem like ifr is zeroed out anywhere. This means that if the second command line argument is equal to the n parameter passed to strncpy (in your case this is only 15 chars) it's highly probable that ifr.ifr_name will not be null terminated.

It seems like a minor complaint, but really this oversight is a basic ingredient needed for an exploit.

Also, your bracing style sucks asshole.
>>
rate my styling code /b/
>>
>>52482205
I hate it when function blocks have the brace on a new line but control flow on the same line like your while there. Seems to be popular for some reason. Do everything in Allman brace or do it in Egyptian brace. Don't mix them.
>>
>>52486912
I rate it Haskell/Trap
>>
>>52482205
Shit way to count bits family. Nice fucking huge tabs too scrub.
>>
>>52481044
Which editor is that? I like the grid.
>>
>>52481044
You only need a printf for table. Separate the strings with a comma.
>>
>using the ugliest language in the ugliest editor on the ugliest DE

Well meme'd op
>>
>>52480593
allman or gtfo
>>
>>52486912

Dead dog/10
>>
>>52487326
dead thread but why is it a shit way? K+R said to use that mask as a quicker way to count bits than using a for loop and checking the first bit to see if it's zero, and then right shifting, which i'm fairly sure it is. Is there a quicker way, or do you just think it's not very explicit what it's doing?
Thread replies: 85
Thread images: 6
Thread DB ID: 435697



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

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

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 shown content originated from that site. This means that 4Archive shows their content, archived. If you need information for a Poster - contact them.
If a post contains personal/copyrighted/illegal content, then use the post's [Report] link! If a post is not removed within 24h contact me at [email protected] with the post's information.