How do you comment code? Over the years I've changed my comment spacing several times, finally settling on:

How do you comment code? Over the years I've changed my comment spacing several times, finally settling on:

void main() {
// sample texture and apply random noise

vec4 tex = texture2D(tDiffuse, vUv);
float scale = 1.0 - tex.r;
float r = tex.r + rand(vUv + time) * 0.02 * scale;
float g = tex.g + rand(vUv + time + 1.) * 0.02 * scale;
float b = tex.b + rand(vUv + time + 2.) * 0.03 * scale;

// comment

for (int i=0; i

Other urls found in this thread:

github.com/ferd36/quaternions/blob/master/include/quaternion.h
en.wikipedia.org/wiki/Fast_inverse_square_root
quora.com/Is-Haskell-as-fast-as-C -If-not-why-not
twitter.com/NSFWRedditGif

to me I don't consider anyone a programmer unless they know how to write shaders

javascript developers would shit their pants at the sight of code that actually does something amazing, instead of modify css colors

I think the space after your comment makes it less readable, they should accompany the block, not be ostracized from it

can you believe the last place I worked on thought that comments "dirty the code"
good luck figuring out what it's supposed to be doing

I comment only function declarations in library headers for Doxygen.
Usually if your code requires comments to understand what it does - then it is crap and should be rewritten in human-understandable form.
And if I really have to use a comment - I use same form as you. Well, actually clang-format does it for me, but I like the result.

>should be rewritten in human-understandable form
thats what the comments are for

how would you rewrite this for "humans"?

if(cubic_spline==true) { // cubic spline interpolation
// setting up the matrix and right hand side of the equation system
// for the parameters b[]
band_matrix A(n,1,1);
std::vector rhs(n);
for(int i=1; i

Function declarations get comments from me. If I make any variable public in a class, I will add a comment on the same line, after the declaration.

//print foo to standard out
void foo();

int i; //iterator

there's no way you write an iterator comment for every int i you make

globals and constants should all be uppercase

for /* for cycle */ (int i /* integer iterator for this cycle */; i < length /* for each element */; i++ /* increment after each iteration */) {
...
}

hahahahahaha

I don't comment code, but when I do, I use VS's XML documentation comments for .NET backed PL

First, by using normal names instead of A, rhs, n, b, c.
Seriously, what the fuck with these names? Does your keyboard have spikes on the keycaps, so you are trying to press them as little as possible?
Second, by adding functions cubic_spline_interpolation and boundary_conditions and calling them, instead of that wall of code. If you are concerned about performance, make them fucking static.

do you think that makes it more readable?
no it doesn't

why do I get the feeling you're a web developer who hasn't coded anything significantly complicated

string comment;
...
comment = "This is actually a comment. It looks like a variable but it isn't used anywhere."

What you posted is an ununderstandabale mess, and the comments does not help it at all.
If you use meaningful variable names and break the logic in several helper functions, you can see what is going on without any comments, by just reading the code.
What if you change the code and forget to change the comment? This happens pretty often, especially during deadlines.

And can you please enlighten me, why are you using those one-letter variable names, non-web-programming guru?
I had a colleague who wrote mess like this because "it is faster to type", but I hope you are not that retarded, aren't you?

I don't

You're both idiots.

Correct variable naming does wonders for comprehension.

However, relying purely on the naming convention is idiocy. Sometimes code needs to be unreadable, and making it readable would impact its functionality.

Use both you niggers. Name your variables intelligently, and comment code when function isn't immediately obvious.

that's how you calculate the points of a spline curve, it's mathematics, you only need the comments to accompany the steps

OH YES, LETS MAKE SEVERAL MORE EXPENSIVE FUNCTION CALLS ON THIS CRUCIAL BIT OF CODE TO DRAW A SPLINE 60 TIMES A SECOND

LETS SCATTER ALL THE CODE INTO 10 FUNCTIONS IN DIFFERENT PLACES WHEN THEY'RE NOT REUSED AND MAKES IT HARDER TO FOLLOW WHAT IS GOING ON

google any quaternion class example and tell me how to rewrite any of the code in "human readable" form

>why are you using those one-letter variable names
from now on just to infuriate people

github.com/ferd36/quaternions/blob/master/include/quaternion.h

what are the correct variable names?

>Sometimes code needs to be unreadable
Literally what?

jdoc


you fucking non java babarians.

en.wikipedia.org/wiki/Fast_inverse_square_root

you nodejs latte lappin webdev soyboys would never have heard of it

you cannot write shader programs in java because it is a bloated garbage language designed for below average programmers and pajeets to be able to code

shaders need real languages

someone post the unintentionally funny "how girls code vs how guys code" post

This kind of claims "hurr durr performance" should be backed by profiling data, which shows that this is a hotspot, especially since you can use inlining, and compliers often inline code themselves without hints.
Following what's going on is already hard, so using functions won't make it worse.
Although if after profiling you realize this should be optimized - then by all means get this all together with comments, this would be a totally valid usecase.

>from now on just to infuriate people
Good luck fixing bugs in your own code in couple years.

>//[My name][today's date][issue ID if there is one] comment

just knowing who wrote a hack and when is a real lifesaver months or years down the road

Dont comment anything else besides methods and classes, or really weird code. Comments make the code unreadable (yes, seriously)

If you really have to resort to this kind of trickery, when you don't know yourself what variables are used to - then this is a valid usecase. Although you should avoid this as much as possible.

see Developing math libraries is hell, and creates shit looking code.

I can already tell youre a NEET "" gamedev"" trash subhuman like innumerable others, who thinks coding a shitty shader in C# is the pinnacle of computer science. That code is shit and so is your variable naming habit. This smug attitude is exactly why you dont have a job, dunning kruger personified

There's a difference between unreadable code and an unreadable or hard-to-understand algorithm.

That code is not unreadable because of the variable names, it's unreadable because the algorithm is a non-obvious solution to the problem.

You're not wrong about the value of performant solutions, but you're not right about readability given that the code in that example is both short and easy to follow.

the penalty hit you get from running a function is unacceptable in high performance applications

if you don't pass giant data structures around, (passing pointers around is still slower than not having to pass them at all), dont reallocate variables in another function to resume the work the first function did, don't use bloated classes, everything will be so much faster

if you just take this approach in general throughout the whole codebase instead of at the last minute to optimise to an acceptable level then your games will run smoothly like quake3 rather than turok on the n64 at 10fps
the faster your code is, the more it can do

I often wonder how much faster all technology would be if programmers were all forced to code with C and functional programming only
imagine how much electricity would be saved as well

I never comment inside methods unless I was forced to do something really weird or mega shit. If I'm commenting inside a method, I'm probably really displeased with what I wrote.

If you're finding it difficult to follow code, it probably needs to be refactored rather than requiring comments.

Obviously that's just a general rule, I have to break it plenty of times.

Clear documentation. You are doing God’s work son.

no shaders are written in C#, you're insane

you know what else uses shaders?
scientific computing
machine learning
blockchains
you know, serious stuff, not babby's first webpage

we'd be still living in caves if held back by you variable name nazis

ITT
>Well, for MY use-case x is the best option, so clearly that must apply to everyone else as well and anyone who disagrees is an idiot

Let me get something straight - do you know what "inline function/method" mean and have you heard about compiler optimizations?

But Minecraft is written in java, and it is one of the most successful games in history!

gamedevs are the bleeding edge of tech
truly pushing the boundaries of computer technology, working under immense pressure, impossible deadlines, writing highly complex low level codebases to juggle graphics, audio, physics, networking at a high framerate

it's not job for women or children
what have you done, made a javascript alert that says 'hello world'?

meanwhile gamedevs create entire worlds, they truly are among the gods of programming
some even say the computer was invented for the sole purpose of creating and playing videogames

>truly pushing the boundaries of computer technology, working under immense pressure, impossible deadlines, writing highly complex low level codebases to juggle graphics, audio, physics, networking at a high framerate
And producing terrible code.

we use them only for small snippets of code like calculating the dot product quickly
inlining a 100 line function is dumb

you cannot always rely on the compiler

minecraft should be banned, it is one of the leading causes of autism, also it's a slow game with low complexity

Yeah, you are pushing limits so hard, that most of the games are unplayable until 1 - 2 patches.
If only you concentrated on quality instead...

thats cause they're western games, not glorious nippon games
japan takes more care with releasing bug free games

also the ability to release patches makes some devs lazy "oh we'll just patch it later"
this wasn't an option in the 80s or 90s, any mistake was expensive to fix

but still japan excels
it's usually western games that are sloppier, even the art is uglier, so its not hard to imagine what kind of cretins write the code

I don't consider anyone a programmer unless they fully verify and implement a filesystem.
*reddit spacing*
Graphics "programmers" would shit their pants at the sight of code that actually works, instead of using ugly hacks to work around vendor-specific issues because they can't be arsed to read the fucking spec (hurr durr it's worth it because it's 200cycles less on this one vendor+arch combo).
*reddit spacing*
I think comments in your personal projects are good as long as you're consistent with them.
*reddit spacing*
Can you believe the last place i worked at thought that comments are an indicator of code-smell? It actually makes sense in an environment where you *have to* follow the spec and don't go around duct-taping shit just to ship week earlier!
t. working on hard-realtime, mostly not even safety-critical

I don't. Comments are for commenting "smart" workarounds and hacks in the software. Properely written code does not need comments. Moreover - presence of comments requires updating them along with the code they comment, which often leads to comment rot and in effect, software being hard to update.

I dealt with 20 year old production code that rotted so far, that comments were essentially useless.

float veryImportantFunction( int _important, int _optionalLimit = 0 )
{
assert( _important > 0 );

float result = 0.0;
const int someConstantValue = 323;
const int arbitraryBoundToLimit = 20;

if( _optional > arbitraryBoundToLimit )
result = 1.0f * ( _important * _optional ) + someConstantValue;
else
result = 1.0f * _important - someConstantValue;

return result;
}

Interesting, care to tell me how is it possible that your system with 16.6ms deadlines has to resort to barely readable optimizations while our system with 5ms deadlines (HFT) can do most of its work in idiomatic Haskell?
Could it perhaps be just that engine programmers are shit at designing performant systems?

Single letter variable names, as well as shortenings are automatic rejections in code review in my job.

I use spaces when I'm making a separate point, I don't care about your dumb rules

Icouldjustomitallwhitespacesinceyouthinkclumpingthingstogethermakesitmorecomprehensiblemaybeishouldwriteafewparagraphsthisway

>code-smell
soyboy detected

>fully verify and implement a filesystem.
considering how shitty most file systems are, that's not an achievement
I've yet to see one that allows for rapid backups to be performed on a drive by keeping track of which files and folders have been modified since the last backup
sure would save the world a lot of time rather than rescan eveeeerything all the time

"Premature optimization is the root of all evil"

So many times this has proven to be true at my job...

because high frequency trading is fucking simple
it's like juggling a single ball
5ms is nothing when the code doesn't have to do much processing

then we know your company makes nothing important

>gamedevs are the bleeding edge of tech

Game devs are the loughing stock of the industry.

there's dumb things people spend time optimising on, but in certain things, every saving adds up

excuse me as I lough at your post

>then we know your company makes nothing important
Well, since you're a gamedev, we know his company is more important that yours :^)

>then we know your company makes nothing important

20 million line code base product that spans back to 1986. It might not be "important" but it sure as fuck is successful.

js/javadoc functions and inline comments in places that I think need them to clarify what's going on.

what is it? the jurassic park control system?

Less them 1% of code is performant and needs hardcore optimisations. That code, with its non-obvious algorithms and optimisations requires _both_ extensive comments _and_ very human readable form of its source. Moreover, it requires a battery of unit tests to confirm that it is cohesive with its specification.

Writing bad code because "hurr durr speed" is an example of trying to hide bad coding practices. Most of such code I had to deal with had to be thrown away on the spot and often it has proven that less complicated algorithms with well delineated abstractions were within 5% of the initial implementation, speed wise.

>I'm have a reading disorder so i don't consider paragraphs enough of a clue. Also ad absurdum
>Hurr durr acknowledging language development makes you a soyboy
>That's not an achievement
That's why there's only one such fs in public space and two in private sector. But writing baby-tier lingebra in GLSL apparently is a huge achievement that separates men from boys.
>HFT is simple
We're not in 2008 anymore, you need to do pretty thorough analysis to be competitive these days. Yes, comparable to what your shitty engine does each frame. And you don't want to see how much proccessing is going on at the seconds granularity.

HDL compiler and simulator with an IDE on top of it.

HFT is straight forward, you're not going to have sudden memory spikes because the user did something that loads a lot of stuff into memory

you just analyse new data, calculate some probabilities and then decide to buy, sell or hold
nothing out of the ordinary

>But writing baby-tier lingebra in GLSL apparently is a huge achievement that separates men from boys.
as close to the metal as you can get baby!
I don't see HFT benefiting the world anywhere near as much as the code that runs on graphics cards

>proven that less complicated algorithms with well delineated abstractions were within 5% of the initial implementation, speed wise
this is what code nazis actually believe with their own self fellating "studies"

ok, that is at least respectable, and does require code to be thorough, you can be admitted to the coding pantheon

Yeah i'm not going to have sudden i/o spikes that i didn't cause, but i have 5ms from the time a packet is rcvd by asic to decide where it needs to be sent, accounting for time it will take that packet to get to the front of the queue, send to and recieve it on given node, proccess it using the data that node works with (the analysis we do is not just basic probabilities, even at the 5ms level you have to counter strategies of your competition which is nontrival and key component of the market performance of your system) and send the proccessed data where it belongs (another trip down the lan).
Most of those 5ms is still spend in the network driver or lan, even with the extensive analysis (mostly written in Haskell, mind you).
And then we have games that do basic lingebra on fractions of our data and still struggle to do it in 16.6ms.
>As close to the metal as you can get baby!
Cool, now write your next game in machine code. It will still be slower than our haskell because you're incapable of designing performant system, so you have to resort to unreadable hacky solutions just to barely keep up.
>I don't see HFT benefiting the world anywhere near as much as the code that runs on GPU
Huh, investing billions into research isn't benefiting the world? We have 2 guys doing their dissertation on our system, and just our system alone has given birth to dozens of articles in the past 5 years.
Needless to say
>using something subjective and not even well-defined as a metric of achievement
>extending "shaders" into "code that runs on GPU"
Let's extend "HFT" to "algorithmic trading" and see which metric you'll have to use to come up on top.

I always leave at least one blank line before a line comment.

none of this is difficult, it's all straight forward
you don't have to worry about ANYTHING unexpected, it's just like flying down a highway, it's not impressive because there's no obstacles

>counter strategies of your competition which is nontrival
none of this comes close to the strategies required for a virtual character to navigate a multi dimensional reality and play properly in networked multiplayer, where it needs to be able to predict where other players may be in 20ms time when packets are lost, or dealing with flakey connections

>haskell
>fast
now you're just baiting with your meme language
quora.com/Is-Haskell-as-fast-as-C -If-not-why-not

>investing billions into research isn't benefiting the world
blockchain can do all that and do it better
your HFT can't actually do any research by folding proteins or analysing telescope pictures for exoplanets, you're just stroking your dick while having no accomplishments

>extending "shaders" into "code that runs on GPU"
thats exactly how its done you fintech dinosaur

>3GB worth of comments in a variable

>None of this is difficult
IEEE disagrees, as it publishes more articles that came from HFT than from games
>Signal analysis in environment where the enemy is using everything he can to hide the signal from you, while doing undergrad-tier lingebra on models that use up to 30 dimensions is easier than baby-tier lingebra in 4 dimensions while doing highschool-tier interpolation
We deal with lost packets too, that's on you to design a good protocol. We also deal with prediction of network topology because, for some reason, our partners decided to use SDN and that's a big issue for deterministic performance.
>Not understanding i point to Haskell *because* it's slower
We can do all this in (mostly) Haskell, you need C++ and obscure hacks for half of that work. The obvious conclusion- engine programmers can't design performant systems.
>Blockchain
Delusional hipster. Our HFT is large part of what made things like BOINC practical. Research into distributed systems funded by HFT is what your protein-folding GPUs use to not run for centuries.
>That's exactly how it's done
Except the compute kernel is written in OpenCL. You don't learn shader programming by learning OpenCL and vice versa. What you learn by writing GLSL for your shitty spiderman game is irrelevant to you when writing OpenCL kernels.

>More published articles = more complex
Oof. Back to the drawing board with that one.

So what algo that was born in gamedev/vfx is used outside gamedev/vfx?

You're still not talking about complexity.

Nice dodge. Mind telling me why almost nobody does dissertation in gamedev while HFT (and fintech in general) is full of it, despite those two areas being the same age?
Is it because it's so complex only nonames from shitty unis do it or because it isn't nearly as complex thus not being an area suited for PhD-level research?

>shitty spiderman game
how dare you!

because gamedevs have more fun making and playing them, than writing dumb academic papers about them read by nobody

without vfx, you wouldn't even be able to see your HFT algos working
HFT isn't useful in an economic collapse

3d slicing vfx algos made 3d printing viable
vfx/gamedev stuff is used heavilly in VR which is applicable for many industries, and especially useful for robotics

Reddit spacing. Get out

THISSS so much this. At least its an easy rejection.
Masters / PhD / FOB new hires on my team are always guilty of this until everyone on the team shitposts on their PR.

git blame works well if available too.

kek

>single letter variable
>no comment

Pick one regardless of what the variable is used for

Underrated post

The code itself should be self documenting, but the abstract of what a module does should be explicitly stated.

...

>gamedevs have more fun
Yes, i've heard the 24/7 marathons months before release are extremely fun. Also, what a preposterous idea that some people have fun both developing new techniques and writing about them. And while academic papers are rarely read by gamedevs (thus their failure to design and implement a robust performant system), they are very often read by people in more competitive environments, where the difference between reading a paper and ignoring it can translate to making millions dollars more (like HFT) or cost lives (avionics, traffic control, ...).
>Without vfx you wouldn't be able to see HFT working
Oh i would, it makes literally zero difference whether you have some nice looking graph or just dump of numbers in a file, moreover i can see my algos working without either because i actually prove them.
Games aren't useful in an economic collapse either. They're hardly useful as is, except for juicing money out of man-children.
>3d slicing
Did you know those algos didn't come from gamedev or vfx? It was the oh so hated academics that invented them, before computers could even draw on a screen.
>vfx/gamedev is used in VR which is applicable in robotics
It's the other way around- robotics fueled the research that you use in VR/gamedev/vfx, like IK.
Summa summarum man-children are consumers, not producers. At least when it comes to shit that "benefits the world".

You've never worked on code that had to interface with anything external or a codebase sufficiently large that you couldn't keep it all in your head at once

Are you saying that that is peak readability? That there is nothing that can be done to improve it? Or are you just using industry conventions as an excuse?