|
BattleMaster posted:Durr hurr Can you post a compact example of code like this? I'm confused and curious to see what it looks like.
|
# ? Jul 25, 2009 04:33 |
|
|
# ? May 14, 2024 21:13 |
|
Nigglypuff posted:Can you post a compact example of code like this? I'm confused and curious to see what it looks like. It's not too exciting, just loads of non-standard type qualifiers and preprocessor directives. I also think that some other features it has are not widely supported, such as anonymous structures, but those are non-essential and wouldn't come into play in that situation.
|
# ? Jul 25, 2009 05:48 |
|
There's also the option of going all-out and writing a new LLVM target. The LLVM stuff is really easy to work with.
|
# ? Jul 25, 2009 05:50 |
|
Avenging Dentist posted:A real man would use the GCC frontend with LLVM to compile to (optimized) C and then compile with the old-n-busted compiler you've got. For writing embedded poo poo that only fits into maybe <128KB of total memory, the complexity / legibility of the code isn't as big of an issue as it would be for much larger systems - there's only so much code you can write in that space (unless you get into awesome mutative poo poo like Synthesis OS, but 128KB hardly has room for a process scheduler). With that little bit of space you're not exactly about to write a TCP Vegas implementation or anything for your tiny web server. On the other hand, I've usually resorted to just going with straight assembly in those situations, which negates the point of LLVM / compiler usage anymore. If you're working with microcontrollers and really small CPLDs, you're probably better off staying with assembly rather than C if you're doing anything serious, old, and proprietary as gently caress. I dunno, writing poo poo just to keep it aesthetically modern when it's targeting completely outdated platforms that nobody cares about seems like a waste of time to me. And I'm someone that loves to tackle poo poo just for the sake of flexing my kung foo.
|
# ? Jul 25, 2009 06:28 |
|
Otto Skorzeny posted:C'mon guys, plenty of people make lovely first posts, our job is to educate them so they don't end up like Victor or Chain Chomp gently caress you
|
# ? Jul 25, 2009 06:35 |
|
necrobobsledder posted:I dunno, writing poo poo just to keep it aesthetically modern when it's targeting completely outdated platforms that nobody cares about seems like a waste of time to me. And I'm someone that loves to tackle poo poo just for the sake of flexing my kung foo. PIC18 isn't outdated, it's one of the newer additions to the PIC families of microcontrollers which are using in billions of devices all over the world. For people who think this is a silly or irrelevant architecture, it's not. There are literally three times as many PICs in the world than there are PCs.
|
# ? Jul 26, 2009 05:15 |
|
How many programmers are there targetting it, though, compared to all of us plebs writing PC or web apps in perl?
|
# ? Jul 26, 2009 05:36 |
|
Vanadium posted:How many programmers are there targetting it, though, compared to all of us plebs writing PC or web apps in perl? Not nearly as many, but that wasn't the point. The point is that there are times when code size still matters and not everyone is a PC babby with an infinite number of garbage-collected languages at their disposal.
|
# ? Jul 26, 2009 06:05 |
|
Trabisnikof posted:Political Science major programmer checking in hi5 buddy. our code is ideologically correct.
|
# ? Jul 26, 2009 06:49 |
|
Mill Town posted:For people who think this is a silly or irrelevant architecture, it's not. There are literally three times as many PICs in the world than there are PCs. For people who think that ants are a silly or irrelevant species, they're not. There are literally 142857 times as many ants in the world than there are humans.
|
# ? Jul 26, 2009 07:10 |
|
Avenging Dentist posted:For people who think that ants are a silly or irrelevant species, they're not. There are literally 142857 times as many ants in the world than there are humans.
|
# ? Jul 26, 2009 07:15 |
|
You can call ants irrelevant all you want but if your house gets an infestation its loving infinity dollars to fix it
|
# ? Jul 26, 2009 07:25 |
|
Avenging Dentist posted:For people who think that ants are a silly or irrelevant species, they're not. There are literally 142857 times as many ants in the world than there are humans. That's the dumbest analogy I've ever seen Edit: I mean it was really bad even compared to your usual schtick. Edit 2: Sorry dude bad jokes are still bad BattleMaster fucked around with this message at 07:53 on Jul 26, 2009 |
# ? Jul 26, 2009 07:42 |
|
BattleMaster posted:That's the dumbest analogy I've ever seen Congrats, I guess you get jokes?
|
# ? Jul 26, 2009 07:47 |
|
Otto Skorzeny posted:"We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil." - Tony Hoare other important words: "small", "97%", and "premature". the point isn't that programmer time is vastly more important than writing efficient code, but that you should work on "small" efficiencies at the end when you're sure you need them AND have a much better sense what parts of your program need to be optimized.
|
# ? Jul 26, 2009 15:35 |
|
you have to measure to find the slowdowns before removing them. the one possible exception is where you write a purposefully and knowingly use piece of slow code, or use a slow library in place of a faster one for ease of development. but even so, it's too easy to be mistaken about possible improvements, and sometimes for a supposedly better algorithm a big-o notation hides really big constant values, or piss poor cache behaviour.
|
# ? Jul 26, 2009 16:10 |
|
There's no point trying to optimize code in a high level language for a PC until there's actually a problem because compilers are usually better than humans at that and there's too much stuff going on behind the scenes. Trying to be clever usually is a waste of time and sometimes results in worse results. Now this discussion about pre-optimization was started when I mentioned that I not only do not program for x86 PCs, but rather 8-bit microcontrollers and I know the limits of the compiler, instruction set, and hardware I'm working with and know what language features to use in certain situations. This is quite a bit different than the bad kind of "pre-optimization" that we're talking about. The system I'm writing for has an 8-bit data bus, no cache, and prefetches only one instruction. It is a RISC machine with instructions that are all 16 bit and take exactly 4 clock cycles to complete. I could probably recite most of the instructions and what they do from memory, because there are only well under 200 of them. I have lots of experience writing assembly and picking apart the code the compiler generates which is often very easy to follow because of the simplicity of the hardware. I'm not some insane code-ninja, it's just that this platform is extremely simple and straightforward. So essentially, it's not pre-optimization to use an unsigned char instead of a signed int because you know the code it generates will be three times smaller in every case. It's not pre-optimization to use switch/case instead of an if chain if you know your compiler will only generate an efficient jump table with switch/case. It's not pre-optimization to avoid large local variables because you know the hardware and compiler sucks at stack operations and requires three times as much code to do them than absolute addressing. Those are more like best practices than optimizations, anyways. If I truly thought I knew better than the compiler I would be using assembly instead. BattleMaster fucked around with this message at 17:07 on Jul 26, 2009 |
# ? Jul 26, 2009 16:55 |
|
Nobody caaaaaaaaares
|
# ? Jul 26, 2009 17:37 |
|
It's not my fault that most people can't imagine programming anything except their pet scripting language. Edit: Oh you know regular expressions? Cool well I'm building alarm clocks and USB-connected instrumentation BattleMaster fucked around with this message at 18:31 on Jul 26, 2009 |
# ? Jul 26, 2009 18:16 |
|
Avenging Dentist posted:For people who think that ants are a silly or irrelevant species, they're not. There are literally 142857 times as many ants in the world than there are humans. MONKEY SPHERE
|
# ? Jul 26, 2009 19:23 |
|
BattleMaster posted:Edit: Oh you know regular expressions? Cool well I'm building alarm clocks and USB-connected instrumentation If you aren't coding for systems with at least 32 GB of RAM you have made some unfortunate life decisions.
|
# ? Jul 26, 2009 20:25 |
|
I prefer premature pessimization because alliteration will never lead you astray.
|
# ? Jul 26, 2009 21:14 |
|
Avenging Dentist posted:If you aren't coding for systems with at least 32 GB of RAM you have made some unfortunate life decisions.
|
# ? Jul 26, 2009 21:16 |
|
BattleMaster posted:It's not my fault that most people can't imagine programming anything except their pet scripting language. Lets get back to the poo poo code, not posts.
|
# ? Jul 27, 2009 01:13 |
|
antpocas posted:Do you ever have nightmares where you find yourself programming MUMPS again? Um, what's a "MUMPS"?
|
# ? Jul 27, 2009 01:55 |
|
code:
I don't think it is an example of coding horror, but it does look weird the first time you see it. RussianManiac fucked around with this message at 02:03 on Jul 27, 2009 |
# ? Jul 27, 2009 01:57 |
|
RussianManiac posted:
Someone posted it a couple of pages ago. http://forums.somethingawful.com/showthread.php?threadid=2803713&perpage=40&pagenumber=66#post363641531
|
# ? Jul 27, 2009 02:11 |
|
mr_jim posted:Someone posted it a couple of pages ago. Wow, and I was thinking about replying "that's not really that bad, it's useful when you have to implement multi-statement macros in C".
|
# ? Jul 27, 2009 02:13 |
|
Avenging Dentist posted:Wow, and I was thinking about replying "that's not really that bad, it's useful when you have to implement multi-statement macros in C". I thought you were joking. Then I read this: http://c-faq.com/cpp/multistmt.html indeed. But using it to avoid an early return, or a goto to cleanup code? That's just silly. mr_jim fucked around with this message at 02:20 on Jul 27, 2009 |
# ? Jul 27, 2009 02:17 |
|
mr_jim posted:I thought you were joking. Then I read this: http://c-faq.com/cpp/multistmt.html Better use that technique than goto. Avoiding early return is stupid tho, i agree.
|
# ? Jul 27, 2009 02:38 |
|
RussianManiac posted:Better use that technique than goto. Avoiding early return is stupid tho, i agree. Why? code:
|
# ? Jul 27, 2009 02:50 |
|
mr_jim posted:Why? It's not. Some people have "OMG goto is evil" beaten into them by idiots who should know better.
|
# ? Jul 27, 2009 03:37 |
|
I stopped using goto after I picked up a language that was more advanced than QBASIC or assembly. Ok sure, its not evil or stupid in all cases, but a nice do while block is nicer looking to me than same with goto statements, maybe just because I didn't see goto in such a long while. In any case the do/while(false) is not any less efficient than similar alternatives, and is about as easy to read/comprehend as anything else.
|
# ? Jul 27, 2009 03:53 |
|
Zakalwe posted:It's not. Some people have "OMG goto is evil" beaten into them by idiots who should know better. They are half right, in that if there is a control statement that clearly expresses what you want to accomplish, you should use it. I figured out what bugs me about this code. code:
If your language supports try/finally, then using that is a better choice because it makes your intent clear. In C, a goto is the next best thing. mr_jim fucked around with this message at 04:06 on Jul 27, 2009 |
# ? Jul 27, 2009 04:02 |
|
RussianManiac posted:In any case the do/while(false) is not any less efficient than similar alternatives, and is about as easy to read/comprehend as anything else. I disagree. Consider the relatively common problem of progressively constructing a resource, which can fail and different stages, requiring different amounts of cleanup. Furthermore, sometimes we can't detect failure without going a conditional or two deeper: code:
In contrast, the version with gotos: code:
And this isn't even considering if there are legitimate uses for do/while in your algorithm, which would make the dual use of do/while for exceptions even worse for someone reading the code.
|
# ? Jul 27, 2009 04:14 |
|
Hand-coding exception handling or destructor emulation in C is nature's way of telling you that you should be using C++
|
# ? Jul 27, 2009 11:52 |
|
mr_jim posted:Why? Ummmmm duh didn't you know that a famous computer scientist said gotos are bad? So obviously we should never use them. And also Knuth said we should never do optimizations because they're evil.
|
# ? Jul 27, 2009 12:27 |
|
dancavallaro posted:Ummmmm duh didn't you know that a famous computer scientist said gotos are bad? So obviously we should never use them. And also Knuth said we should never do optimizations because they're evil. http://pplab.snu.ac.kr/courses/adv_pl05/papers/p261-knuth.pdf
|
# ? Jul 27, 2009 12:42 |
|
dancavallaro posted:Ummmmm duh didn't you know that a famous computer scientist said gotos are bad? So obviously we should never use them. And also Knuth said we should never do optimizations because they're evil. You're right. I fixed the code to avoid gotos, ugly do/while hacks, and still have a single point of exit! code:
|
# ? Jul 27, 2009 12:43 |
|
|
# ? May 14, 2024 21:13 |
|
mr_jim posted:You're right. I fixed the code to avoid gotos, ugly do/while hacks, and still have a single point of exit! Thanks, that's much better! Doesn't that feel good?
|
# ? Jul 27, 2009 13:24 |