Berkeley CSUA MOTD:Entry 12891
Berkeley CSUA MOTD
 
WIKI | FAQ | Tech FAQ
http://csua.com/feed/
2025/05/24 [General] UID:1000 Activity:popular
5/24    

2004/3/27-28 [Computer/SW/Languages/C_Cplusplus, Computer/SW/Languages/Python] UID:12891 Activity:moderate
3/27    Funny argument involving code, recursion, and a foxtrot comic:
        http://www.pantsfactory.org/?action=comments&linkid=1260
        \_ somehow that thread neglects to provide a link to the 1.0.1 patch:
        \_ somehow that thread neglects to provide a link to the patch:
           http://homepage.mac.com/billamend/images/patch.gif
2025/05/24 [General] UID:1000 Activity:popular
5/24    

You may also be interested in these entries...
2012/7/19-11/7 [Computer/SW/Languages/C_Cplusplus] UID:54439 Activity:nil
7/19    In C or C++, how do I write the code of a function with variable
        number of parameters in order to pass the variable parameters to
        another function that also has variable number of parameters?  Thanks.
        \_ The usual way (works on gcc 3.0+, Visual Studio 2005+):
               #define foo(fmt, ...) printf(fmt, ##__VA_ARGS__)
           The cool new way (works on gcc 4.3+):
	...
2011/2/5-19 [Computer/SW/Languages/C_Cplusplus] UID:54027 Activity:nil
2/4     random C programming/linker fu question.  If I have
        int main() { printf("%s is at this adddr %p\n", "strlen", strlen); }
        and soda's /proc/sys/kernel/randomize_va_space is 2 (eg; on)
        why is strlen (or any other libc fn) at the same address every time?
        \_ I don't pretend to actually know the right answer to this, but
           could it have something to do with shared libraries?
	...
2006/7/13-18 [Computer/SW/Languages/C_Cplusplus] UID:43667 Activity:nil
7/13    How do you get milliseconds in C? I want to do something like:
        t1=sec;
        long_operation_that_needs_to_be_benchmarked();
        t2=sec;
        printf("This operation took %f seconds", (t2-t1));
        \_ You could try using clock() and CLOCKS_PER_SEC.
	...
2005/6/21-23 [Computer/SW/Languages/Perl] UID:38230 Activity:high
6/21    My math and/or perl fu is weak. Is there a way to get integer
        multiplication in Perl the way it's done in C? i.e. limiting
        to 32 bits. Like 1588635697 * 1117695901 = 1166976269 in C.
        \_ Can't you just multiply and then mask all but the last 32 bits?
           \_ I don't think so; that's not the same as mult overflow.
              > perl -e 'print (1588635697 * 1117695901)'
	...
2004/8/30-31 [Computer/SW/Languages/C_Cplusplus] UID:33228 Activity:high
8/30    Ok this is pretty basic but... is there a way to "escape" text to
        avoid it being substituted by C preprocessor macro expansion?
        \_ Wouldn't that functionality make C preprocessing as powerful as
           lisp's quasiquote/escape? -- ilyas
           \_ Squish!  Isn't it illegal to talk about lisp on the motd?!
        \_ In general no.
	...
2004/8/18-19 [Computer/SW/Languages/C_Cplusplus] UID:32995 Activity:very high
8/18    Doesn't math.h define min() and max() functions?  What should I include
        to get them?  I'd rather not do the (a < b) ? a : b thing.  Thx
        \_ No.  Many programmers define it as a new macro.  Don't know what
           gcc people do, offhand.
        \_ OS X has fmin(3)/fmax(3) which conform to ISO/IEC 9899:1999(E).
           Linux might have these too.
	...
2004/7/5 [Computer/SW/Languages/Perl] UID:31164 Activity:high
7/4     Is there something like a macro in Perl?  Couldn't find any in
        the Camel book.
        \_ If you truly need macros in Perl, you probably want AUTOLOAD.
           Of course, if you truly need macros, Perl is the wrong language for
           what you are doing.  -- ilyas
        \_ I don't know perl, but don't almost all interpreted languages have
	...
2004/5/13-14 [Computer/SW/Languages/C_Cplusplus] UID:30202 Activity:very high
5/12    nCircle is looking for an experienced software engineer.  See
        /csua/pub/jobs/nCircle.sweng
        \_ so I have been doing java, and I still believe I'm an expert
           c/c++ programmer.  However, if you ask me what are
           the printf format parameters, I doubt I could tell you much
           other than %s.  So I can definitely get a book on c/c++ and
	...
2004/5/11 [Computer/SW/Languages/C_Cplusplus] UID:30157 Activity:high
5/10    Can I create arbitrary blocks of code in C without control structures?
        I really just want something I can "break" out of.
        GetLock(myLock);
        {
          rc = SomeLibraryCall();
          if (rc < 0) break; // breaks to release lock
	...
2003/9/17-18 [Computer/SW/Compilers] UID:10234 Activity:nil
9/17    For this snipet of code:
        for (i = 0; i < 3; i++) {
            printf("\n\n0x%x %d", ptr++, *ptr);
        }
        Is there anything machine dependent about the evaluation of ptr++?
        I tried this on sparc/solaris and *ptr prints out the value AFTER
	...
2002/11/18 [Computer/SW/Languages/Java, Computer/SW/Languages/Functional] UID:26574 Activity:very high
11/17   How come printf("%f\n", 1/10); returns 0.000000?
        \_ because it is? go read up on integer division.
           \_ gosh how dare you ask someone to rtfm.  how rude of you not to
              spoon feed someone on the motd.  I'll bet you're not a pine
              user either.
              \_ Gosh, how dare you correct someone on the motd without the
	...
2002/7/13-15 [Computer/SW/Languages/C_Cplusplus] UID:25351 Activity:moderate
7/13    how do i pass variables to the system in C ?  e.g.
         system("echo input is %s", argv[1]);
        results in "input is %s" but I want the system to see argv[1]
        (I know i can just use printf, but not for what i really want to do).
        \_ sprintf into array, pass array to system?
        \_ so write your own function that takes a variable number of
	...
2013/4/9-5/18 [Computer/SW/Languages/C_Cplusplus, Computer/SW/Apps, Computer/SW/Languages/Perl] UID:54650 Activity:nil
4/04    Is there a good way to diff 2 files that consist of columns of
        floating point numbers, such that it only tells me if there's a
        difference if the numbers on a given line differ by at least a given
        ratio?  Say, 1%?
        \_ Use Excel.
           1. Open foo.txt in Excel.  It should convert all numbers to cells in
	...
2012/12/18-2013/1/24 [Computer/SW/Languages/Perl] UID:54561 Activity:nil
12/18   Happy 25th birthday Perl, and FUCK YOU Larry Wall for fucking up
        the computer science formalism that sets back compilers development
        back for at least a decade:
        http://techcrunch.com/2012/12/18/print-happy-25th-birthday-perl
        \_ I tried to learn Perl but was scared away by it.  Maybe scripting
           lanauages have to be like that in order to work well?
	...
2011/12/23-2012/2/6 [Computer/SW/Languages/Python] UID:54272 Activity:nil
12/23   In Python, why is it that '好'=='\xe5\xa5\xbd' but
        u'好'!='\xe5\xa5\xbd' ? I'm really baffled. What
        is the encoding of '\xe5\xa5\xbd'?
        \_ '好' means '\xe5\xa5\xbd', which is just a string of bytes; it has
           length 3.  Python doesn't know what encoding it's in.  u'好' means
           u'\u597d', which is a string of Unicode characters; it has length 1,
	...
2011/4/16-7/13 [Computer/SW/Languages/Python] UID:54086 Activity:nil
4/16    Whoa, I just heard that MIT discontinued 6.001 (classic scheme)
        to 6.01. In fact, 6.00, 6.01 and 6.02 all use Python. What the
        hell? What has the world become? It's a sad sad day. SICP forever!
        \_ old story, they've ditched that shitty book and lang for a while.
        \_ I used to think scheme was cool, then I saw Ka Ping Yee's
           "Beautiful Code" class aka 61a in python, and converted.
	...
2011/2/24-4/20 [Computer/SW/Languages/Java] UID:54048 Activity:nil
2/24    Go Programming Language.  Anyone here use it?  It kind of
        reminds me of java-meets python, and well, that is fitting given it's
        a GOOG product.  What is so special about it?
        \_ as I understand it, it's a suitable OOP-y systems language with more
           structure than C, less complexity than C++, and less overhead than
           Java/Python.
	...
2011/3/31-4/20 [Computer/SW/Languages/Python] UID:54070 Activity:nil
3/20    Has anyone here had success in using python 3.0?  Any gotchas
        to worry about? I've got an entire set of apps in python 2.x
        and am wondering if it's worth it to upgrade?
	...
2010/8/8-9/7 [Computer/SW/Languages/C_Cplusplus, Computer/SW/Languages/Web] UID:53914 Activity:nil
8/8     Trying to make a list of interesting features languages have
        touted as this whole PL field comes around, trying to see if they
        have basis in the culture of the time: feel free to add some/dispute
        1970 C, "portability"
        1980 C++, classes, oop, iterators, streams, functors, templates
             expert systems
	...
2010/8/12-9/7 [Computer/SW/Languages/Perl] UID:53922 Activity:nil
8/12    Ruby coders, do you mostly DIY your stuff or use the ruby libs out
        there?   How is their quality compared to other libs you have used
        for other langs?  Thx.
        \_ I use Ruby for hobby stuff, etc.  I use libraries for system stuff
           (web access, process, etc.) but that's about it.  Perl libraries are
           much better/more complete.  I assume because of the maturity and
	...
Cache (4322 bytes)
www.pantsfactory.org/?action=comments&linkid=1260
Okay, Ive seen it done a lot, but hes gonna have trouble when he starts doing languages much more insistent on using the entry functions canonical signature. My main gripe with that part, tho, is that if hes gonna depart from standard in making main TAKE void, why not make it RETURN void too? Sure, void is one more char than int, but hed get to drop the whole return 0; Re: Thu, Mar 25, 2004 08:09 PM GMT viega The lack of newline doesnt concern me. The result should be illegible, just like all the other scrawl Ive been forced to do for a teacher. The mainvoid thing is actually a very good thing to do, but NOT in that context. The explicit denotation of void for the parameter list denotes that the function never takes any arguments. This is in stark contrast to , which is often used that way, but in C actually means that the arguments could be anything one would have to use va macros or something like it to read the arguments. Sat, Mar 27, 2004 07:01 PM GMT dave Sure, Ill go learn the main idioms of a language, like when Matt tasked me to write some stuff in Python, which I had read about before but never actually seen. What you seem to condone, though, is assuming that the future maintainers will learn the idioms, and be skilled and alert and so on. I dont think this is a good assumption to make, when the cost of doing otherwise is merely a few extra characters at least, now that disk space is so cheap. As for recursion, that would still require a way to compare the number of times it has recursed, to the number desired. Sure it could check the stack or something contorted like that, but a variable is still at least the obvious way, unless maybe you dont consider an argument a variable. Even so, why be so worried about one variable, if youre going to create a whole stack frame for each recursion level? Sat, Mar 27, 2004 07:20 PM GMT viega Dave, recursion in that context isnt an efficiency issue, its a style issue. Tail recursion can be compiled just as efficiently as iteration, but thats beside the point. My whole point is that programming style is not even close to a science. Look at the massive flame wars over whether Pythons indentation is a good thing or a bad thing. Theres no right answer, as much as some of us prefer the Python way which, by the way, doesnt involve braces. Sat, Mar 27, 2004 11:49 PM GMT dave Execution efficiency wasnt the reason I was objecting to using recursion for this. Using recursion where iteration is more natural, or vice-versa, generally leads to code that is less clear. Yes, there are times when iteration may be more natural in one language, while recursion is more natural in another, for the same task. I dont care about the extra milliseconds a CPU may spend on the problem unless of course it will be executed a gazillion times. What concerns me more is the extra time a programmer has to spend figuring out WTF a piece of code does, and how, so he can make some fix or other change. Unclear code can multiply severalfold the time it takes to grok code in fullness. Ive been that poor sod too many times not to be concerned about that. Off the top of my head no Im not gonna bother trying them, compare: void WriteStringNTimesRecursive char str, int times if times > 0 printf sn, str; Sure theres probably a counter internally, but its not a variable the programmer has to bother with. As for idioms, yes, learning them including whether recursion is generally favored over iteration is part of the job, but frankly idioms is a minor consideration. The main danger is just plain old making of mistakes, whether due to being unaware of idioms, mistakenly assuming there was an opening brace before an indented line, everyday stupidity, etc. Surely youve seen your share of incompetent programmers, who still somehow manage to get hired to work on complicated stuff. Sun, Mar 28, 2004 07:31 AM GMT viega Uhhh, I find them both perfectly clear. Certainly dont hire such people in any company Im ever involved with. Anyway, I certainly agree that there are cases where iteration is far more natural for most C programmers. And, there are cases where one of the two is so clearly a more appropriate construct that the other ends up being far less clear. And, much of the time, either construct is clear enough that its more a personal preference.