Coding Quickie: Handling Periodic Numbers with C++ Templates

Sdílet
Vložit
  • čas přidán 5. 03. 2023
  • In this throw-together video I handle numbers that wrap, periodic numbers, using some C++ template trickery. It's not optimal. It's not clever. But it does server to illustrate how complex templates can make your program.
    Source: github.com/OneLoneCoder/Javid...
    Patreon: / javidx9
    CZcams: / javidx9
    / javidx9extra
    Discord: / discord
    Twitter: / javidx9
    Twitch: / javidx9
    GitHub: www.github.com/onelonecoder
    Homepage: www.onelonecoder.com
  • Věda a technologie

Komentáře • 111

  • @UliTroyo
    @UliTroyo Před rokem +36

    It hadn't occurred to me that I didn't know how to handle this problem! There's some math(s) you encounter so often outside of programming, you just assume you'll know how to implement it.

  • @RomanRembolovich
    @RomanRembolovich Před rokem +14

    just wanna say a couple of good words for the author. thank you a lot. appreciate all the job you do to help people learn. thank you a lot for reinventing the wheel and detailed explanations of all fundamental concepts. there are not a lot of people on youtube who really create valuable content as you do.
    and especially wanna say great thank you for "code it your self" series. many people who "teach" people on youtube don't even know how their code works, but you suggest creating your own library just because you do not want to use external resources. it's just the greatest Wow I ever had when I was learning something. it describes you as a great professional.
    one more thank you for all the job that you doing to promote codding community and educating people. hope you doing well. wish you all the best.

    • @javidx9
      @javidx9  Před rokem +8

      Thank you very much for your kind words! Some more C-I-Y videos on the way this year!

  • @AJ-zt4bb
    @AJ-zt4bb Před rokem +20

    Man, really appreciate your videos, have learnt a lot from them , keep up the good work!

  • @AJSquirrel53
    @AJSquirrel53 Před rokem +1

    Thanks again for the awesome video Javid! Your videos never fail to teach me something new, even in the quickie ones!

  • @bogdanflorescu8338
    @bogdanflorescu8338 Před rokem +15

    2:47 the math works out, it does not end on 40°. It s like subtracting 2 vectors. V - U is the vector from U to V. Likewise 20 - 340 means -320 starting from 340, and that is 20. On the previous one as well. 340 - 20 means 320 from 20 to 340. I m not tring to be THAT GUY, I really apreciate your content and I find it interesting and helpful, but I got confused for a sec so I mentioned it for the others as well.

  • @lucklessgeek9886
    @lucklessgeek9886 Před rokem +2

    The use of the term "periodic numbers" had me a bit confused. I expected this to be related to handling for repeated decimals.
    I think this was more useful than what I was expecting though, so that was a nice surprise.

  • @CodeParticles
    @CodeParticles Před rokem

    Love these mini snippits! Reminds me of those refreshers you used to upload on polymorphisms, pointers, lvalue rvalue concepts. Please do more of these! Love it~ 👍👍

  • @wesleythomas6858
    @wesleythomas6858 Před rokem

    Great stuff as always. I actually understand this problem totally and a big thanks as I’ll be implementing it this way myself. Such a tidy and intuitive implementation

  • @nothke
    @nothke Před rokem +2

    Woah, I finally understand what decltype is! I tried reading the definition or watching other videos about it, and just couldn't get it until now. Thank you so much!

  • @DaTux91
    @DaTux91 Před rokem

    This was a fun little video! Exactly the kind of thing I love to get into.

  • @8NLD8
    @8NLD8 Před rokem +2

    man you're a genius, I'll learn c++ and I swear I'll wach every video of yours

    • @theintjengineer
      @theintjengineer Před rokem +1

      That's it, Mate! Don't do ugly rust or slow python hah

  • @JustPlayingBroGD
    @JustPlayingBroGD Před rokem +3

    16:39 - the story of modern man surrounded by cameras in every f*****g place )

  • @Impatient_Ape
    @Impatient_Ape Před rokem +3

    Using 360 degrees is just a convention. If you define some new angular measure -- like a "binangle" -- so that some power of 2 is defined to be a full circle, then you can just use (unsigned?) binary arithmetic to implement the modular math, as all angles would be limited to a specific number of bits. You would just write functions to convert degrees to "binangles" and vice-versa.

    • @andrewdunbar828
      @andrewdunbar828 Před rokem +2

      That's what I used to do on the ZX Spectrum and Amiga in assembly and C. I used to use the magic number 256 for many things. Just bitwise and with 255 to do a modulo or just use an 8-bit type and the underflow and overflow used to be the same as a modulo for free. I figured some of it out at the time on my own. I think I didn't know about modulo and hadn't learned radians but knew the term from calculators and had a hunch I was using something similar to radians since I at least knew I was using a digital analogue of degrees without the seeminlgy arbitrary 360 that would slow everything down massively.

    • @jcamargo2005
      @jcamargo2005 Před rokem +1

      Exactly. This also aligns with the 2-complement representation: 0xFF = 255 is the same as -1. abs(x-y) will automatically return the 'smallest angle'

    • @jcamargo2005
      @jcamargo2005 Před rokem

      @@andrewdunbar828 360 comes from the Babylonians, it was chosen because it has many factors, making easier to divide by 2, 3, 12, 30, etc... For the same reason of convenience, we might pick 256.

    • @Impatient_Ape
      @Impatient_Ape Před rokem +2

      @@jcamargo2005 Yes. And using *unsigned* integers for angles works too, as the modulus happens automatically by the bit-cutoff. 8-bit example: 0=256=full circle. So 250+12=6 and 250-255=251.

    • @andrewdunbar828
      @andrewdunbar828 Před rokem +1

      @@jcamargo2005 Yes numbers like 12 and 360 are magic in another way that I surely didn't care about for the kind of stuff I was coding back then (-:

  • @CykPykMyk
    @CykPykMyk Před rokem

    It's a sin to not watch this, and very disappointing to not see millions of views under your videos. You are awesome teacher and I hope you'll live long and healthy!

  • @janusmcgee8909
    @janusmcgee8909 Před rokem

    Thanks for the practical application of that decltype

  • @painsme2
    @painsme2 Před rokem

    Excellent video.

  • @motbus3
    @motbus3 Před rokem +2

    Thank you for finding some time between work and family for these videos!
    Quick q: will you talk about c++ concepts someday ? I mean c++20 concepts (which are named compile-time predicates which constrain types)

  • @ddummer
    @ddummer Před rokem

    Wonderful! I made a computer controlled 360 degree plate that you can stand on a while ago using an arduino controlling the plate by getting a degree from the computer and it will position the plate through a motor and a rotary absolute position sensor based on the shortest distance from the last degree... so here I got the correct way of doing things it instead of my homemade "it works" code. ;)

  • @davidporterrealestate
    @davidporterrealestate Před rokem +1

    I learned so much from this video

  • @RPG_Guy-fx8ns
    @RPG_Guy-fx8ns Před 4 dny

    You could use int16, move the range to between -17999 to 18000. You don't need degrees larger than 180.00, unless its for display, in which case you can just add 36000 if its negative.
    Or just use power of 2 numbers to represent 90 degree angles, and take advantage of numbers that already wrap.
    16 bits contain 65535 values, so 65535 URots in a circle. -32,768 to +32,767 Rots.
    make a look up table that approximates sine and cosine and write your own atan2 for Rots and URots.
    only convert to degrees when rendering the number, degrees aren't actually good for math.

  • @DFPercush
    @DFPercush Před rokem

    When I needed to calculate the acute difference between two headings, I used
    headingAngleDiff = 180 - angmod(setHeading - heading - 180.0, 360);
    where angmod uses while loops to add or subtract 360 as seen here.
    If you want to see that on desmos, paste
    180\ -\ \operatorname{mod}\left(s-x-180,\ 360
    ight)

  • @emilycs8823
    @emilycs8823 Před rokem +1

    great explanation of Decltype. I really was failing to understand Decltype from other literature.

  • @vincentcleaver1925
    @vincentcleaver1925 Před 9 měsíci

    Now I want to do the eyeball thing as a animation for Halloween

  • @pilotandy_com
    @pilotandy_com Před rokem +2

    I don't know what that shape at the beginning of the video was, but I can use some of this stuff for my flight planning (wind direction) software. Thank you!

  • @jcamargo2005
    @jcamargo2005 Před rokem +1

    This type of problem maps perfectly to modular arithmetics

  • @denisstryszyk4354
    @denisstryszyk4354 Před rokem

    Quick but good!

  • @vriska222
    @vriska222 Před rokem +1

    im sorry if this is the wrong place to ask but is there a chance we could get a (dedicated) video on dialogue systems? ur videos are a fantastic resource and id love to see ur approach to them (outside that rpg series from a while back)

  • @femboy.owo7
    @femboy.owo7 Před rokem +2

    my lord i love u

  • @oschonrock
    @oschonrock Před rokem +4

    very nice. And good example. I actually think this would be much better as a strong (ranged) type with operator overloads. And the "negative difference"? It should be a separate type IMO. just like ptrdiff_t. There is also much duplication in the functions. And that would not make it "object oriented". It would just be a strong type. Implicit conversions to that type can be provided if desired. I wouldn't though.

  • @ratchet1freak
    @ratchet1freak Před rokem

    when dealing with angles I prefer to hold a sine/cosine pair and then do operations on those. That completely removes the need to worry about wrapping. Though it won't handle multiple turns nicely.

  • @Kaltinril
    @Kaltinril Před rokem +1

    The "eyes flipping" is the exact same behavior I always had for my "heat seeking homing missiles" in my SHMUP game.
    I found a solution that uses the cross product that doesn't use Arc tangent that worked. I haven't really looked into the MATH on it, but it works.
    //Get the vector to move from 1 point to the other
    float dist_to_waypoint_x = target.X - position.X;
    float dist_to_waypoint_y = target.Y - position.Y;
    float facing_x = (float)Math.Cos(rotation);
    float facing_y = (float)Math.Sin(rotation);
    float crossProduct = (dist_to_waypoint_x * facing_y) - (dist_to_waypoint_y * facing_x);
    float floatElapsed = (float)gameTime.ElapsedGameTime.TotalSeconds;
    if (crossProduct < 0)
    // turn left
    rotation += (maxRotation * floatElapsed);
    else if (crossProduct > 0)
    rotation -= (maxRotation * floatElapsed);
    //Add the velocity * the direction
    velocity.X = maxVelocity.X * (float)Math.Cos(rotation);
    velocity.Y = maxVelocity.Y * (float)Math.Sin(rotation);
    Granted this is C# but you get the idea.

    • @Triszious
      @Triszious Před rokem +1

      Wouldn't this solution make the rocket oscillate when facing its target? You also have the special cases where the target is directly behind or in front of the rocket heading, which would return 0. It also seems like your rotation angle is unbounded, which if there's one takeaway from this video, you should avoid. Keep the angles within the range of the atan2 function (-180, 180] and you will never have these kinds of issues again.

  • @gorkemvids4839
    @gorkemvids4839 Před rokem +4

    Dude, why did you stop talking to the camera? It was nice to see a friendly face talking about programming.

  • @x_flies
    @x_flies Před 11 měsíci

    “90% or the world’s code is just hoping for the best.” 😂 king! Thank you for that. Because I usually start praying before compiling and I’m not even religious hehehehhe.

  • @gedaliakoehler6992
    @gedaliakoehler6992 Před rokem

    Cool video. Didn't know about decltype - neat. I also have been enjoying the regular uploads :)

  • @dreamdrunk539
    @dreamdrunk539 Před rokem

    As a game developer, i do this stuff everyday lol. But it was a really fun video to watch anyways.

  • @NoNo-fl6oq
    @NoNo-fl6oq Před 11 měsíci

    good afternoon. what can you advise a green novice to include in winapi and msdn MFC ?

  • @conkerconk3
    @conkerconk3 Před rokem

    Another example of this is if you have a 3D camera that rotates around the Y axis (or Z if you're that kinda guy), you typically wrap the angle between, i think, negative PI and PI, because if that angle gets large enough, sure the matrix operations will still work but you lose precision as the float value increases
    I think it's something like past 1 million for a float32, you only have a precision of like 0.06, which is no good for rotation in PI

  • @ic6406
    @ic6406 Před 10 měsíci

    As a professional game engine developer I get used to whiles in the code. One of my function contains several whiles within a while and works super fast because it decays to some or a single repeat and handles a lot of edge cases

  • @DeathSugar
    @DeathSugar Před rokem

    it's called modular number systems. periodic numbers are float and have repeating part after fraction point, like 1/3 = 0.(3) or 0.(123456789) and so on

  • @devgamez8527
    @devgamez8527 Před rokem

    I remember way back using game maker i struggle with this exact problem, after a while i came up with this script:
    angle = dir - tdir; // my curent direction - target direction
    if (abs(angle) > 180) {
    if (dir > tdir) {
    angle = -1 * ((360 - dir) + tdir); }
    else {
    angle = (360 - tdir) + dir; } }
    return abs(angle)

  • @CodeTalker23
    @CodeTalker23 Před rokem

    4:27 cracked me up LOL

  • @GameBacardi
    @GameBacardi Před rokem

    Nice

  • @hossamhassan8270
    @hossamhassan8270 Před 5 měsíci

    how to start making mini projects like this I struggle with the beginning of the project and how to put things together ?

  • @ZomB1986
    @ZomB1986 Před rokem

    Have you ever considered migrating to VSCode (so others without VS or even Windows, can tag along)? or even VSCodium (the de-telemetrized VSCode). I know it's a slog to set up, but it's what others use most (I think).
    I like these short videos (not to be confused with Shorts, which I hate).

    • @javidx9
      @javidx9  Před rokem +10

      Thanks! No. Code is code, very rarely do I write anything specific to windows, and the code doesn't rely on the IDE. So whether it's VS, notepad, MS Word, it doesn't change.

  • @rishapkumar5509
    @rishapkumar5509 Před rokem

    Hey I really appreciate your videos. Iam trying to learn making applications for windows with gui in mind. I think me and a whole lot of ther people would appreciate a code along for a basic project just us in terms of how to mix logic behind a program with gui

  • @stickmasterlukeRBX
    @stickmasterlukeRBX Před rokem

    the "while" still hurts

  • @janminator232
    @janminator232 Před rokem

    Cool

  • @lambichlambrovski9956
    @lambichlambrovski9956 Před rokem +5

    Very interesting. This video reminds me why I quit C++, but ironically it's the reason why I like it so much! I love how much freedom you can have with C++ code, but it's the kind of freedom that lets you not just shoot yourself in the foot, but blow your leg off when you don't know what you are doing!

  • @pruebauno9529
    @pruebauno9529 Před rokem

    muy buenoooooooooo

  • @b.c.34
    @b.c.34 Před rokem

    Hi JavidX9....i have been having issues in knowing the linux syntax/ function of same relevance as Windows _khbit(). To make matters clear "i do not know the linux variance of Windows _khbit() and _getch() functions needed for asynchronousity."...i have search all websited but couldn't find any...
    Thanks

  • @sdfrtyhfds
    @sdfrtyhfds Před rokem +1

    Why are you not use modulo?

  • @__hannibaal__
    @__hannibaal__ Před rokem

    Very smart and simple idea, and i m shame that i can’t interpreted in algorithm despite i m mathematician; and i m going to use very complex function from special functions tables with double periodic.
    I try to make one for period T and with single argument
    Template< type name T, T Period> circular(T a);
    Templatecircular(complex Z, T Priodx, TPriody); or passed to template parameter maybe better//
    Thanks for idea;

  • @Shifticek
    @Shifticek Před 11 měsíci

    Why did you use in one while >= and in other only

  • @__hannibaalbarca__
    @__hannibaalbarca__ Před rokem

    What about a char and int,
    I think is periodically value if get out of range ,

    • @DFPercush
      @DFPercush Před rokem

      char + int would promote (cast) the char to an int. It would also be sign extended unless it was an unsigned char.

  • @b.c.34
    @b.c.34 Před rokem

    Nice.....

  • @skeleton_craftGaming
    @skeleton_craftGaming Před rokem +1

    could've you not done something like constexper auto circ_add(const auto lhs, const auto rhs...

  • @aaronpeapell
    @aaronpeapell Před 11 měsíci

    If inputs -> 0..360
    int diff(int a, int b, int range)
    {
    int c = a - b > 0 ? a - b : b - a;
    return c > range / 2 ? range - c : c;
    }

  • @krzysztoflasota5808
    @krzysztoflasota5808 Před rokem

    Dear @javidx9 please clear my doubts about the correctness of your algorithm. It works perfect, unfortunately only for rmin=0 periodic numbers.
    Let's consider an example for 0°:360° range numbers:
    270° (75% period) + 90° (25% period) = 360° == 0° (0% period)
    540° (150% period) + 90° (25% period) = 630° (175% period) == 270°
    Correct results.
    But for 10:30 range numbers, where 10 (0% period) == 30 (100% period) example as above:
    25 (75% period) + 15 (25% period) should give result 10 (100% == 0% period) but your algorithm's result is 40 aka 20 (150% period)!!
    40 (150% period) + 15 (25% period) = should give result 25 (175% == 75% period) but your algorithm's result is 55 aka 15 (225% period)!!

    • @DotcomL
      @DotcomL Před rokem

      circ_add cannot take as inputs numbers like yours which are defined in another space

  • @japedr
    @japedr Před rokem +3

    Suggestion: std::fmod could be useful to avoid the while loops, although the sign must be carefully taken into account.

    • @maix52
      @maix52 Před rokem +1

      While true, it kinda defeats the point of using templates.
      Here javidx9 wanted to let the compiler take the type that would fit the result. Wouldn't fmod make it an floating point ?

    • @japedr
      @japedr Před rokem +1

      True, I guess we could use something like "if constexpr (std::is_floating_point_v)" to decide to use either fmod or just "%".

  • @gwynbleidd9000
    @gwynbleidd9000 Před rokem

    is your username derived from two lone swordsman?

  • @empireempire3545
    @empireempire3545 Před rokem +5

    As much as I dislike OOP and 'Modern C++' style, this is one case where i would make a new composite type and write all functions as operator overloads. Its just so much nicer down the way to be able to use + instead of circ_add(), and performance-wise it should be the same...

  • @BrendonHolden
    @BrendonHolden Před rokem

    In fiction one could use the time spiral, the class could go from 20 to 340, and the circular number is the truth simply by losing their minds. (Looking deep in the mind: there are copies of the 1:00, just a little over near where 340 would be.) It is something to think that DNA spirals…
    I do not recommend this, I mean I am not dead, and instruction is everything; yet it is fiction, I am a must have in anybody’s library, I must write!
    C++ kills right? Yes, but what does that mean my good man?
    -Brendon
    3/9/23

  • @imanalien4129
    @imanalien4129 Před 5 měsíci

    why that code is not working in xcode?

    • @javidx9
      @javidx9  Před 5 měsíci

      Let me install the correct version of my psychic debugging tools. I've tried to telepathically read the output on your screen, but your firewall is in the way.

    • @imanalien4129
      @imanalien4129 Před 5 měsíci

      @@javidx9 yeah, I followed other of your projects but when I write in xcode it just shows a lot of errors, I think you're using windows and i'm using mac

  • @dmitrystatnikov9806
    @dmitrystatnikov9806 Před rokem +2

    Did you consider to use operators / and % to get rid of the loops?

    • @user-dg5br2lx1k
      @user-dg5br2lx1k Před rokem +1

      He just say that % is expenssive operation to keep a good O(I) time, that because they do it that way.
      Cause in the future may be if you will working with the server data - you will need fast managing terrabytes of datas and billions of throws. You will need fast operation skills.

    • @oracleoftroy
      @oracleoftroy Před rokem +1

      @@user-dg5br2lx1k I wish he had profiled it. Sure, % is expensive relative to -, but how does it actually compare to the loops? And the loops put a sequential constraint on the calculation, whereas the mod is one operation that can take advantage of instruction reordering and pipelining, so I'm not sure if in practice that the loops win out. But who knows what tricks compilers can pull off?

  • @gokhancakr661
    @gokhancakr661 Před rokem

    i started learning c++ with your engine but even in the example program i am only getting 100-150 fps . why is that? my pc aint that slow . tried drawing decals on the screen and after 1000 decals fps dropping to 10 - 15 fps. can someone help me with that?

  • @0ia
    @0ia Před rokem +1

    Don't templates slow down build times more than a bit?
    Though I'm not really sold that templates would be better than having manually-created float and double variants of the functions - it feels more readable to me in code, and the debug info is better.
    I suppose I don't mind a bit of extra typing to have those long-term benefits, and maybe that's the fundamental difference?

    • @oracleoftroy
      @oracleoftroy Před rokem +1

      It's not that simple, and it's certainly not going to blow up compile times with such a small example like this. The compiler does a bit more work, but it's not bad when you use them appropriately and don't turn your entire program into a templated implementation. If you need an int and a float version, with a template it parses the template and stamps out two versions for each type. If you do it manually, it parses nearly the exact same code twice. I doubt you'd even be able to measure a significant difference in timing, and writing the code once and having only one place to update it should it need to change is a lot easier than maintaining many different implementations of essentially the same code.
      The main issue is when you have a lot of them that need to be shared in headers and used in multiple compilation units, as the templates need to be parsed and expanded multiple times. If you heavily use templates to generate a lot of code, it will slow down compilation, but that's true of macros or other code generation techniques. There are ways to reduce or reuse that work (e.g. extern templates, precompiled headers, modules).
      And of course, since templates work at compile time, you can use this to precompute some values rather than calculate them at runtime. If you do more compile time calculations, you will spend more time compiling. But this isn't anything special about templates, it's true of any language with a compile time computation. I remember Jon Blow complaining about templates being Turing complete and 'slow' because of it, then a few weeks later showing off how his language can play an entire video game at compile time. Talk about inflating compile times! It shows how disingenuous this complaint often is.
      Its never a good idea to force a language feature or design pattern or anything else into your code just because you can, but if templates solve real problems for your code base, there's no reason not to use them.

    • @0ia
      @0ia Před rokem

      @@oracleoftroy Thank you, I will keep this in mind in future :)

  • @zxuiji
    @zxuiji Před rokem

    0:45, sorry but I have to correct you here, those are just arbitrary numbers we as humans assigned, in reality those should be
    0,1,2 & 3
    For normalised space since each CURVE of the circle is a separate side, like the 4 sides of a square, it just happens that it looks like one side. Took me a fair bit of thought but I figured out how to make those curves using only integers, angles included, it required treating the range of the angle as just the normalised result shifted across a bit, you use the boolean result of which half of the range it falls in to decide to assign it to x or y accordingly with the value you assigned to one having a 3rd added onto it, this 3rd comes from the pixelated form of circles always ending up in a 1,2,1,2 pattern as it curves

    • @javidx9
      @javidx9  Před rokem

      I like pi

    • @zxuiji
      @zxuiji Před rokem

      @@javidx9 Didn't say you shouldn't use pi, just saying that floats are not needed to generate curves, circles etc, I remember reading that there used to be systems where floats didn't exist, so no pi, if you or someone else were to try to create a retro game for those systems then it would be nice to know there is a way to generate curves without floats

  • @duality4y
    @duality4y Před rokem

    being within the range is a big assumption haha you dont know how a user will misuse your function :D

    • @javidx9
      @javidx9  Před rokem

      Then they pay the price for using things they don't understand. I think it's a fair assumption. There are not many legitimate circumstances you would add 5 and 20000 degrees for example. Multiplication needs care, but that's why I wanted to retain the ability to use regular type, so I can use the correct utility for the different tasks.

  • @Katniss218
    @Katniss218 Před rokem +1

    Why are you using different types for the different sides in the function? It makes no sense to me really.

    • @oracleoftroy
      @oracleoftroy Před rokem

      It makes it nicer to use in the face of type promotion.

  • @empireempire3545
    @empireempire3545 Před rokem +2

    More properly those numbers exist in a -ring-, not range.

  • @Jkauppa
    @Jkauppa Před rokem

    algorithm: give all angles indices from a list directionally between two angle limits (when the selection side is clear, ie left of this angle, and right of this angle)

    • @Jkauppa
      @Jkauppa Před rokem

      try diy radix sort super fast sorting algorithm

    • @Jkauppa
      @Jkauppa Před rokem +1

      why dont you just implement mod as a div

    • @Jkauppa
      @Jkauppa Před rokem

      btw, for the plane-ray grid renderer (wofl3d or doom style), breadth first search flood fill gets you fast all the possible walls/areas to render (possibly), and in order

    • @Jkauppa
      @Jkauppa Před rokem

      breadth first search in a 2d/3d grid can be fast draw in order ray tracing/casting first approximation (draw triangles in order to get a bounce z-buffer image of the scene), ie place objects/triangles in a dynamic updated grid only, then draw triangles in order of the grids, can be an collision detection octree too

    • @Jkauppa
      @Jkauppa Před rokem

      you can mark screen scan lines (vertical and horizontal) as drawn or not drawn, to speed up checks, if you use the breadth first search triangle draw order (dont render a scan line h/v that has already been drawn before, mark is as drawn)

  • @anon_y_mousse
    @anon_y_mousse Před rokem

    And here you illustrate one of my complaints regarding committee driven design. Why did they use decltype instead of the more commonly used and obviously better, for that matter more consistent with the language's roots, term of typeof. This is a rhetorical question, but it's frustrating to see bad decisions going into modern C++. I can at least understand why they did such a boneheaded thing with constexpr instead of just changing the way const works and then some. After all, they don't want to break existing code, so they can't just reuse terms and make them work more like they should work, but come on, at least make it something better than constexpr. It's annoying to type because it has the same prefix and does some of what const should already do. I would've happily settled for Const, since we have case sensitivity. I know some will accuse this argument of being bikeshedding but syntax and keywords in a programming language do matter and can make or break a language.

    • @oracleoftroy
      @oracleoftroy Před rokem

      This shows an advantage of design by committee. _typeof_ is a very common name, so if just one guy in his basement was coding the language and chose this name for his 30+ year old language used all around the world in millions of codebases, he would immediately create problems for just about everyone. But by having input from multiple compiler implementors and users of C++, they noticed the issue and chose a name that is still very descriptive and far less likely to create issues.
      Likewise, I think _pure_ might have been a better name, but constexpr isn't bad and it still tells you what it is does. I think these examples of naming choices aren't even worth worrying about unless the name is misleading. Yes, names could have been different, but who cares? It's tough to add new keywords to a widely used and old language like C++ while avoiding breaking everyone. They practically have to avoid anything that is common to avoid breaking people. No one wants their code to be constantly broken by language updates.

    • @anon_y_mousse
      @anon_y_mousse Před rokem

      @@oracleoftroy Problem with that thinking is what it's used for, and typeof not only would make more sense, but there's precedent for not using declspec because several major compilers already had extensions using that exact keyword and for a different context. What's more is it is misleading because in one instance it was used to get the type of an operation after all promotions and that type wasn't actually declared in that context nor could it have been based on the operation. Oh sure, one of the types in the operation was declared, but the resulting type after operating on them was not explicitly declared and was in fact the reason for needing such a keyword so that it could be determined. Of course, this is exactly why design by committee is such a bad thing, people argue no matter which way they decide. It's also why changing the design after years of use for a language is such a bad thing, because any change will always affect someone.

  • @swrh
    @swrh Před rokem +2

    FIRST!

    • @swrh
      @swrh Před rokem +3

      @Kiwi Kyles Isler Because we’re dumb.

    • @DFPercush
      @DFPercush Před rokem +1

      What with the 1-based indexing, is this a Lua video?

  • @user-zq8bt6hv9k
    @user-zq8bt6hv9k Před rokem

    Clean code is horrible, the function without template was good enough. Just duplicate the code for other primitive type

    • @oracleoftroy
      @oracleoftroy Před rokem +2

      That sounds like a minefield to maintain. Just write the code once like he did in the video, it's very clear. If the code isn't very clear, learn the tools.