5 ms·
This is a fun idea, but it generates comments that are typically the ones which should not exists in actual code, because they do not add any useful information
by p4bl0 5y ago
This is a fun idea, but it generates comments that are typically the ones which should not exists in actual code, because they do not add any useful information. Thinking about it I'm not sure it is possible to do better. If the comment can be automatically generated from the source code, then the source code itself will necessarily a be more precise version, making the comment useless. The benefit here is that at least the comments are automatically updated at the same time as the code…
- micvbang 5y agoThis reminds me of https://imgur.com/gallery/dZe8k https://imgur.com/gallery/dZe8k :)
- mike_hock 5y ago/** Half the number ** ********************* ** Multiplies the number by one half (0.5) */ float x2 = x * 0.5F; /** Copy the number ** ********************* ** Stores a copy of the number in a new variable */ float y = x; /** Pointer cast ** ****************** ** Take the address of the number, ** cast the pointer to a pointer pointing to long, ** and dereference that pointer, ** then store the result in a new variable. */ long i = * ( long * ) &y; /** Subtract and shift ** ************************ ** Shift the number one bit position to the right, ** then subtract the result from the constant 0x5f3759df */ i = 0x5f3759df - ( i >> 1 ); /** Pointer cast ** ****************** ** Take the address of the number, ** cast the pointer to a pointer pointing to float, ** and dereference that pointer, ** then store the result in an existing variable. */ y = * ( float * ) &i; /** Multiply twice, subtract and multiply again ** ************************************************* ** Multiplies the number by itself, ** then multiplies the result by the other number, ** then subtracts that from the constant three halfs (1.5), ** then multiplies that by the number. ** The original number. ** The first number. ** You know what I mean. */ y = y * ( 1.5F - ( x2 * y * y ) ); /** Multiply twice, subtract and multiply again ** ************************************************* ** Multiplies the number by itself, ** then multiplies the result by the other number, ** then subtracts that from the constant three halfs (1.5), ** then multiplies that by the number. ** The original number. ** The first number. ** You know what I mean. ** This can be removed. */ // y = y * ( 1.5F - ( x2 * y * y ) ); /** Return from function ** ************************** ** Returns the number */ return y;
- BulgarianIdiot 5y ago> This is a fun idea, but it generates comments that are typically the ones which should not exists in actual code, because they do not add any useful information The point is attaching meta info to values which aren't pointless. Say: weight = 42 /* pounds */; It's kinda like types, but without the type checks. I'm not purely sarcastic, because boxing values within objects so they have a type has drawbacks. That said, there are better way of typing values without boxing them.
- sparsely 5y agoF# does exactly this, except it understands the rules of units cancelling etc.
- Anunayj 5y agoWoah TIL. I've been looking for a similar language, something that I can do Physics in without having to worry about units/constants. Till now I've used WolframAlpha or just Google. Do you think F# is suited for this, or do you suggest other alternatives?
- sparsely 5y agoF# definitely has the most complete implementation that I've seen, I'm sure other languages would let you hack something together though. https://docs.microsoft.com/en-us/dotnet/fsharp/language-reference/units-of-measure https://docs.microsoft.com/en-us/dotnet/fsharp/language-refe...
- gregwebs 5y agoActually this would be quite useful not for the traditional role of comments but instead to debug program flow.