Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. The Weird and The Wonderful
  4. If only there were a language construct to handle this case...

If only there were a language construct to handle this case...

Scheduled Pinned Locked Moved The Weird and The Wonderful
database
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    lewax00
    wrote on last edited by
    #1

    Just stumbled across this:

    int page = 1;
    while (true) {
    if (page > pageCount) {
    break;
    }

    /\* Do stuff with page \*/
    
    page++;
    

    }

    Considering how common it is to use an index in a loop, you'd think the language designers would have a better way of dealing with this... :laugh: EDIT: even better, in 2 of the 3 places using page, it uses page - 1 :facepalm:

    R 1 Reply Last reply
    0
    • L lewax00

      Just stumbled across this:

      int page = 1;
      while (true) {
      if (page > pageCount) {
      break;
      }

      /\* Do stuff with page \*/
      
      page++;
      

      }

      Considering how common it is to use an index in a loop, you'd think the language designers would have a better way of dealing with this... :laugh: EDIT: even better, in 2 of the 3 places using page, it uses page - 1 :facepalm:

      R Offline
      R Offline
      Rob Grainger
      wrote on last edited by
      #2

      If I use ILASM to disassemble .NET coe, it frequently decodes for-loops like this. Maybe the original developer appropriated (ie. stole) some code using similar techniques without checking the output carefully. (Personally, I use it to check correct usage of poorly documented APIs, but I'm sure many are less scrupulous).

      "If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.

      L 1 Reply Last reply
      0
      • R Rob Grainger

        If I use ILASM to disassemble .NET coe, it frequently decodes for-loops like this. Maybe the original developer appropriated (ie. stole) some code using similar techniques without checking the output carefully. (Personally, I use it to check correct usage of poorly documented APIs, but I'm sure many are less scrupulous).

        "If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.

        L Offline
        L Offline
        lewax00
        wrote on last edited by
        #3

        Rob Grainger wrote:

        it frequently decodes for-loops like this

        Of course, the simplest way to write a loop in an assembly-like language is something like:

        // for ([assignment]; [condition]; [increment]) { [body] }
        [assignment]
        start_loop:
        if ![condition] goto end_loop
        [body]
        [increment]
        goto start_loop
        end_loop:

        That doesn't mean it should be written that way in a high-level language though, even if you technically can.

        D 1 Reply Last reply
        0
        • L lewax00

          Rob Grainger wrote:

          it frequently decodes for-loops like this

          Of course, the simplest way to write a loop in an assembly-like language is something like:

          // for ([assignment]; [condition]; [increment]) { [body] }
          [assignment]
          start_loop:
          if ![condition] goto end_loop
          [body]
          [increment]
          goto start_loop
          end_loop:

          That doesn't mean it should be written that way in a high-level language though, even if you technically can.

          D Offline
          D Offline
          Dan Neely
          wrote on last edited by
          #4

          Rob's suggesting the duhveloper just stole recompiled code out of reflector without thinking; and building in logic to detect all 90 bazillion high level constructs and correctly promote the result of reflection to them instead of the simplest valid code is 99.9999% of the work involved in writing a reflection tool. The length of the long tail means that it's a job that will probably never be done.

          Did you ever see history portrayed as an old man with a wise brow and pulseless heart, waging all things in the balance of reason? Is not rather the genius of history like an eternal, imploring maiden, full of fire, with a burning heart and flaming soul, humanly warm and humanly beautiful? --Zachris Topelius Training a telescope on one’s own belly button will only reveal lint. You like that? You go right on staring at it. I prefer looking at galaxies. -- Sarah Hoyt

          R 1 Reply Last reply
          0
          • D Dan Neely

            Rob's suggesting the duhveloper just stole recompiled code out of reflector without thinking; and building in logic to detect all 90 bazillion high level constructs and correctly promote the result of reflection to them instead of the simplest valid code is 99.9999% of the work involved in writing a reflection tool. The length of the long tail means that it's a job that will probably never be done.

            Did you ever see history portrayed as an old man with a wise brow and pulseless heart, waging all things in the balance of reason? Is not rather the genius of history like an eternal, imploring maiden, full of fire, with a burning heart and flaming soul, humanly warm and humanly beautiful? --Zachris Topelius Training a telescope on one’s own belly button will only reveal lint. You like that? You go right on staring at it. I prefer looking at galaxies. -- Sarah Hoyt

            R Offline
            R Offline
            Rob Grainger
            wrote on last edited by
            #5

            Thank you for saving me the effort, exactly my point.

            "If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups