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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
U

User 11783308

@User 11783308
About
Posts
34
Topics
0
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • You ever produce code you know is stupid, but you don't know a better way to do it?
    U User 11783308

    It is not often, but there are times in C++ when there is no alternative but to duplicate code. That is when macros come to the rescue. Due to the need for exactly the same code in several related methods, I will sometimes group those together, add a macro #define _someName with the code, expand the macro in each method, and add #undef _someName at the end of the group of methods. Sometimes there just aren't any alternatives. In one case, I had an abstract base class that was essentially inherited in a diamond pattern to get the clean user interface that I wanted. But, even though there was no data in the abstract base class, a subclass either had to have two instances thus pointlessly increasing the size of the overall objects, or it had to be virtual, increasing both size and decreasing performance. There was no need for any of that because it was only providing an interface, with a default implementation of methods that only relied on other methods that were virtual. I wound up with two parallel lines of inheritance, with many methods duplicated between the lines. Invisible to client code (not the library code though), but there were no restrictions on size or performance. Yes, the virtual methods do require data -- but in the vtable, not in the code. And it is possible for the vtable to be optimized with global optimization (which is already being done at link time) so that multiple vtables are not required. Recently, I created an experimental class, which required macros of templates because a template cannot contain a name used in code. A bit strange, but it worked and the user interface was reasonable. That, fortunately, never made it into my library since I had better options. Even in C++ macros are very useful. They really, really need to be made more general with looping, variables, etc. There are places that I could use all of those features. Just like in older assembly languages. And why do macros have "elif", but neither C nor C++ do? Guess what? I use a global macro #define "elif else if". I also define "block", "loop", "when", "unless", "until", etc. I could do more with better macro features. There seems to be a belief that if a language is good enough, that macros are simply obsolete and should be eliminated. That is false. There is no such thing as a language that is good enough. And never will be. C++ certainly isn't. I will always want more in a language (which is why I use C++, even though it is very limited) and I don't have an extra decade or two to design and build a better one.

    The Lounge announcement c++ database com

  • Okay, old guys unite, what smartphone do you have?
    U User 11783308

    I bought my first dumb phone about 15 years ago. I replaced it with my first smartphone about 8 years ago. It was, and is, the first Google Pixel XL. Still going strong, original battery. I only did that because I needed it for a class. Recently, I had reason to look at getting a newer phone. I couldn't find anything under about $1,500 that was better. Apparently, those are now called gaming phones. Almost every phone had worse display resolution -- which actually makes a difference, I tried side by side comparisons and text was fuzzy on the newer phones, but crisp on mine. The other specifications were not really any better. Worse, most of them do not have a headphone jack, nor did they have two USB ports, or a separate power port. That is a non-starter and major deal breaker. The GPXL has a screen resolution of 2560x1440. I will move up to 4k, but not down. I also can't justify the cost of a used car for a phone they want me to replace in a year or two. I expect a phone to last a couple of decades. At least. It turns out, that outside of making phone calls, getting confirmation texts from various accounts, about the only use I actually have for the phone is reading Kindle books and .pdf documents (which is why the resolution matters, I want to see the entire page without scrolling, and for it to be readable).

    The Lounge ios mobile question

  • Okay, old guys unite, what smartphone do you have?
    U User 11783308

    Mine was flagged as spam also. I did not anything that should have triggered that. Just a straight forward reply.

    The Lounge ios mobile question

  • Random question: Free code
    U User 11783308

    I usually think that this is something that will take me more time to ensure that it works correctly, reformat it to be readable, shoehorn into my existing project, make it work with my compiler and operating system (hint: not Linux), etc. that I am far better off not touching it. If for some reason, I have lost my sanity, then I would examine the license -- usually to find that I can't use it anyway (since nobody has every paid me to work any anything non-proprietary).

    The Lounge question lounge

  • Do you even bother with tech books anymore?
    U User 11783308

    In just the last couple of months, I have spent several hundred dollars on tech books. I probably spend several thousand yearly -- and have done so for the last half century. I own around 20,000 books -- not all tech (around 1/3 to 1/2 were my late wife's books). Unfortunately, most are currently in storage. Just on the bookcases near me, there are probably between 600 and 1000 tech books. These are not manuals, technical documentation, cooking books, and very little has anything to do with Microsoft. What you find on the internet is typically low level, and random stuff someone felt like putting up. But, especially for tech, there is a huge amount that still only in books -- and that is likely to be true for a very long time. Good luck on donating books. I have more than the local public library. There is no way in hell that they would accept my books if I died. They would try to sell some, most of the rest would be donated somewhere like Habitats for Humanity, who in turn would eventually burn them. Fortunately, the tech books probably could be donated to a local public university. They might even take some of the fiction. I suspect cooking books are going to be homeless.

    The Lounge question architecture lounge learning

  • No your line is too long.
    U User 11783308

    With a readable size font, my maximum line length is 544 characters with 135 lines on the screen. I could do more with a slightly smaller font or perhaps a different font. That is not to say that I have written lines that long, I don't actually know how long that would be. We are not using punched cards anymore, we are not restricted to fan-fold paper -- who actually uses paper anymore? There is no unacceptable maximum for either the number of lines in a method / function or the length of a line. In both cases, I would expect the set of lengths to be a power distribution. Where the vast majority of function / line lengths are very short, and very long lengths would be extremely rare -- but no upper limit. The length of either a function or a line should be considered on a case by case basis. There are many times that the most important information in a line of code occurs in the first 20 or 30 characters. The best readability may be a very, very long line because the majority of the time the remainder of the line is not of interest when reading code. If there is a problem with lines that are too long, get a better monitor. My primary monitor is a 50" 4k monitor (actually TV, but that replaced a failed 48" 4k monitor because it was something like $200 instead of $2000). When available, and when I can afford it, my next monitor will be 55-65" and 8k. Even without a better monitor, just scroll left / right or up / down.

    The Lounge com question announcement

  • Recommendation: Domain Registrar, and why
    U User 11783308

    I use dynadot, they are cheaper than anything else that I have found, and I host with qth. While qth is small, they are very responsive and very cheap.

    The Lounge question

  • What's the Most Concise, Human-Understandable Practical Language?
    U User 11783308

    Well, just in terms of the JavaScript, here is how I would write it.

    var home =
    {
    cit : "Boston"
    };

    home.city = function(aCity)
    {
    if (arguments.length)
    this.cit = aCity;
    else
    return this.cit;
    };

    Yes, the function is a bit longer but there is only one function instead of two and writing pointless "get" and "set" is no longer necessary. That is a holdover from languages which do not have true getter / setter type attributes. I would note that the function would normally be part of a class (or prototype) and not the object itself. In C++, it takes more work, but you can write code so that you can literally write

    aCity = home.city;
    home.city = aCity;

    I usually don't do that, but I do do the same thing in C++ as in JavaScript. Note that brace placement may make it look longer, but that is matter of style. Braces are part of a statement block, so I indent the same as the statement block. And don't use unnecessary braces. The make code less readable. I agree with you about APL not being readable. Perl has a lot of the same characteristics. I disagree about COBOL, it is both far less concise and far less readable. If something is too concise, it becomes unreadable. But, conversely, when it is too expansive (non-concise?) then it is also less readable. A straight mathematical expression whether in a conditional or an assignment is generally maximally readable. Assuming that the length and complexity of the expression is not too large. And that weird and strange operators (APL) are not in use. So languages whose basic structure is similar to C tend to be most readable without becoming too concise.

    The Weird and The Wonderful javascript python com game-dev tools

  • about $2k to $2.5k to spend on a dev machine this year, need CPU recommends
    U User 11783308

    It is not as critical as you might think. I am still using a 3770k with 32G. It has 4 cores (8 threads) and I can (and have) run a half dozen different VMs at the same time, and never use more than 25% of the CPU. While I certainly won't recommend a CPU that old, pretty much any more modern CPU should do the trick. I would recommend water cooling -- not necessarily a custom setup, but a "complete" system. They are nearly the same cost as a fan. Just put one in my daughter's new computer. Otherwise when your CPU does pull out all of the stops, the fans can get pretty noisy. I do not game either -- however, I use a 1080 graphics card. Not for framerate, but to get good high resolution and for use in parallel applications. And a SSD for drive C is essential. The system is old, but other than a couple of GPU upgrades, it has been more than adequate development. Now, if you need very large data storage, your cost can rise substantially by the time you implement a good RAID (preferably RAID 6).

    The Lounge game-dev question learning

  • Win 10 USB DIagnostics
    U User 11783308

    I was having a similar problem. I could right click on an item -- and it could take 30 seconds for the popup menu. All sorts of things like that. It was not every time, but frequent. It started after an upgrade and upgrading to 1909 fixed it. So, I suspect it was one of the mitigation fixes that was causing the problem -- even after Microsoft supposedly fixed the problems. So, if you haven't upgraded to 1909 -- and it went very smoothly for all four machines here -- I would recommend it. The problem might not be with the USB ports.

    The Lounge help question lounge

  • Just because you can doesn't mean you should.
    U User 11783308

    You are absolutely correct. Both of us missed parts of the expression. That is why I would more likely use the first variant I gave rather than the second one. And probably would write neither in practice, but without a wider context can't say what I would actually write. It would probably involve some restructuring.

    The Lounge question cryptography learning

  • Just because you can doesn't mean you should.
    U User 11783308

    I stand corrected. I missed the double decrement (sorry, it has been a long and intense semester, I'm not fully back up to speed). Multiple increments or decrements of the same variable are undefined according to the standard. Sequencing might make it OK, but that can't be assured. There might be a corner of the standard that allows it with the sequencing, but I wouldn't assume that it is legal. The intent of the original logic appears to be: Given a key r, to search two hash tables, in order. If a match is found, then r should be assigned the index returned from the matching hash table, reduced by one for indexing into the "commands" table. The difference between your code and the original is that the original reassigns "a" after the "or". That is intended to wipe out any previous changes to "a". Your code does not do that so it will potentially get a double increment. To match the intent of the original, one of the following tweaks could be used (minor formatting applied -- note that I use "and", "or" and "not" to reduce errors caused by mixing up & and &&, or by mixing up | and ||).

    action a;
    if ((a = hash_table[r]) and not cmdcmp(commands[--a].name, p)
    r = a;
    else if (a = short_hash_table[r]) and not cmdcmp(commands[--a].short_name, p))
    r = a;
    else
    r = -1;

    This has an extra assignment -- that the compiler can optimize away by merging identical blocks. A more interesting alternative is

    action a;
    if ((a = hash_table[r]) and (a = a - 1, not cmdcmp(commands[a].name, p)) or
    (a = short_hash_table[r]) and (a = a - 1, not cmdcmp(commands[a].short_name, p)))
    r = a;
    else
    r = -1;

    which makes use of the comma operator. Decrement is not directly used, but the compiler will generate the same code, but lifted before evaluating the function call's parameters.

    The Lounge question cryptography learning

  • Just because you can doesn't mean you should.
    U User 11783308

    Both the operator precedence (and thus the order of evaluation) and short circuiting are part of the C language definition and is not compiler dependent. The compiler can only reorder the expression during optimization if it can ensure that it does not change the result. It is quite safe to rely upon. This expression already has a sufficient number of parentheses, more just makes it less readable. I'm not even sure where you would even put extra parentheses.

    The Lounge question cryptography learning

  • Style and form in generated code
    U User 11783308

    I do the opposite when I generate code. When emitting code, I automatically indent (really, fairly trivial) and even emit occasional comments. The reason is very simple -- I do not do so, so that users can maintain or modify the code, I do it so that I can maintain and modify the code generator. Just like any other code you write, code that you write automatically may need to be corrected for errors, large and small. Just because you do not directly maintain the generated code, does not mean that the code generator does not need to be maintained. Clean, formatted generated code helps substantially with that. And, if one or eleven years, your code generator is not still in use (or possibly not even available), but the generated code is still running. Then it DOES need to be maintained directly. Bottom line, treat generated code exactly like any other code that you write. BTW, GOTO statements are fine regardless -- just use them to replacing missing control structures. Every language has them, including C and C++. For example, break and continue only apply to the inner level. I quite frequently need to break from two or (more rarely) three levels. Using a GOTO is the only choice, when the language is insufficient.

    The Lounge design ai-coding business tutorial question

  • How many lines-of-code does a developer write (life time)?
    U User 11783308

    All of these different methods are simply a volume metric and are roughly correlated. But, consider that for a blank link you have to hit the enter key. For a comment, you actually have to type it. For code you also have to type it. For both code and comments you have to think about it and since the comments are about the code, that is relevant. Documentation outside of code also counts in the same way, but probably stripping off the formatting is reasonable. So, simply take the size in bytes of all of the source files. Perhaps it would be worth while to compress each one and then total the size. That would tend to reduce the effect of spaces / tabs and repeated variable names and the length of variable names. Compressing everything together would result in too much reduction in size due to similarities across programs that don't really reflect much. I have found that, in practice, a simple volume metric is a very good predictor of performance and and time required to complete a project.

    The Lounge android com tutorial question discussion

  • Maybe we DO need professionals licensing
    U User 11783308

    I don't usually join in these discussions, nor am I claiming that this is the best way to accomplish the task. However, I see more of a problem with the compiler -- these are not really nested blocks. They are "else if" statements and not really different from a case statement in a switch except that you are using an expression instead of a constant. When I write them, the formatting shows that. Every "else if" is at the same level and there is no nesting. In C (and C++) you have "#elif", but for some godforsaken reason, you don't have "elif" in the language. This is a missing control structure and why the hell is there any kind of a fixed limit on parsing the language? I seriously doubt that, once parsed, that the control flow graph has any sort of limit, but limits like these are from 30 or 40 years ago. Inexcusable in today's world.

    The Lounge question tools help workspace

  • Git
    U User 11783308

    I also use SourceSafe, and have for many years. It not only works well, it organizes the repository exactly the way that I want. That doesn't seem to be the case for anything else I have investigated. Worse, there do not appear to be any tools to migrate a SourceSafe database. I also have never had a integrity failure. I have never used Git, but may have to for a current project, or more accurately GitHub, just as a permanent place to park some public code.

    The Lounge help visual-studio collaboration tools question

  • A message for every programmer in the world. Bar none.
    U User 11783308

    There are a few points that are relevant here. First, a recent study found that more experienced people are more closed-minded about new or different concepts in their field. Further, other people thought that was justified because of their experience. So, some of the resistance to new concepts comes from that area. It has always been the case that to make major advances in a field of knowledge it is necessary for the older generation to die off or retire. This is a problem in every field. All you can do about it is to try to be aware of the tendency in yourself and avoid it whenever possible. A non-computer example is set theory which allows a set to be a member of itself. This is accomplished by removing the Foundation Axiom (which explicitly prohibits it) and tweaking the definition of identity. It has been shown that such a set theory is consistent if and only if normal set theory is consistent. But, it allows so much more to be done, is a complete superset of normal set theory and avoids many problems. But, the older generation either completely rejects it, or sidelines it as a curiosity when those working in the field should have been all over it. Second, sometimes a "package" result is really required because the effort of developing it yourself is prohibitive. As a personal example, I am extremely good with mathematics. However, it has been several decades since I last used Calculus or Differential Equations (I use mathematics daily, just not in that area). So, if I need something that is expressed or derived using those tools, I would need to spend weeks or months coming back up to speed on the needed mathematical tools. When experienced people in a field can provide a relative simple set of rules or guidelines, or a canned generic solution that is definitely worthwhile. It is not the same as trying to get someone to do your homework. An example here is the FFT (Fast Fourier Transform) or Wave Packets. It is not necessary to understand the derivation of the transform when all you need is an algorithm. It is possible to understand the underlying concepts without wading through the mathematics. Suppose you want to transform an audio file in some way. All you really need is an algorithm. Your task has almost certainly been done many times before. There are many people with a solid understanding of the mathematics and of the algorithm. They can easily provide assistance that is extremely valuable to a fellow programmer that just needs to add a minor feature to a product. Management might allow a co

    Article Writing question game-dev business help tutorial

  • Keyboard Rant
    U User 11783308

    What would we do without the scroll lock? If you set HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\i8042prt\Parameters\CrashOnCtrlScroll = 1 and the press <ctrl> + <scroll lock> you will generate a BSOD! Including a current memory dump. Surely this is in every programmer's repertoire!

    The Lounge help html com question

  • You got someone in your team like this?
    U User 11783308

    What else are you supposed to do when you get up at 9 or 10 pm? Perhaps he's a night owl like so many other programmers (especially older ones that were forced into that mold due to mainframe availability). Personally, I don't like to get up until the sun goes down. I think better at night and there are far fewer distractions. If I get up in the daytime, especially on an early schedule, I just drag around until evening and don't really get up to speed until after midnight. Note that I will be going to bed in a few hours. Staying up early! It really annoys me when I can't go to the bookstore at 3am.

    The Lounge collaboration question
  • Login

  • Don't have an account? Register

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