|
Crazy Mike posted:As my office switches to .NET, eventually we are going to have a talk about new naming conventions. Our current variable naming convention is <scope><datatype>_variablename like string ls_user_name or long ll select_count or boolean ib_read_only. What is the argument against having scope and datatype in your variable names? It's arguable that if you have so many variables/members that you need to track their types that way, then it's a sign you need to refactor. If you aren't able to read a variable or member name and immediately tell what its doing (either due to poor naming or an abundance of orthogonal purposes in the same component), then it's likely time to think about breaking things down into functional subcomponents.
|
# ? Dec 10, 2012 07:31 |
|
|
# ? Jun 7, 2024 12:19 |
|
Titan Coeus posted:This is the case. Page 165. And if we're about C, main returns 0 implicitly as of C99, and functions used to be implicitly int up until C99 (at least, I think that's when both changes were made), so you can usually get away with this in a single program: C++ code:
|
# ? Dec 10, 2012 11:18 |
|
Aleksei Vasiliev posted:There are Java implementations that require you to import anything in java.lang? It used to be the case (Java 1.0 - 1.1 era IIRC) that you had to import from java.lang. I specifically remember having to import java.lang.String during CS class in uni. I hated java for years due to 1.1.
|
# ? Dec 10, 2012 13:56 |
|
mobby_6kl posted:And if we're about C, main returns 0 implicitly as of C99, and functions used to be implicitly int up until C99 (at least, I think that's when both changes were made), so you can usually get away with this in a single program: Ironic that the "cpp" code flag is there because that isn't valid C++.
|
# ? Dec 10, 2012 14:48 |
|
Otto Skorzeny posted:I need* to... I hate when people do this and forget to add the other *. I spend hours of my life searching for it.
|
# ? Dec 10, 2012 14:51 |
|
NtotheTC posted:I hate when people do this and forget to add the other *. I spend hours of my life searching for it. *Since the C compiler will assume that any function that lacks a prototype returns an integer and takes however many arguments it is called with, and the only function I'm calling is printf (and I haven't screwed up its invocation), and a standard version of printf is almost certainly in an object file that will get linked by default, it is very probably that a program that "forgot" to include stdio.h would still compile (with a warning, unless you have passed it flags to treat warnings as errors) and run correctly, even though the include ought to be there.
|
# ? Dec 10, 2012 15:22 |
|
A couple notes on that. First, if your function is defined with a prototype that takes a float, calling it through an unprototyped function type will probably fail, because default argument promotion (the thing that happens when you pass a variadic or unprototyped argument) turns floats into doubles. This ridiculous special case is brought to you by DIGITAL, which did not want to support float natively and somehow felt that this terrible language hack would help. Second, your specific example of printf is unportable. C does not guarantee that calling a variadic function through an unprototyped function type will succeed, and indeed, there are platforms which pass variadic arguments differently from how they pass non-variadic arguments; MIPS is the most prominent one. Usually what this means is that variadic arguments are always passed on the stack. In the abstract, that's much smarter than matching the non-variadic convention, because the non-variadic convention usually wants to pass different types of arguments in different registers, and piecing that all together in a way that matches the normal convention requires a gratuitous amount of code in variadic prologues and va_next. The problem is that it potentially breaks ancient code relying on unprototyped function calls, and platform ABI designers are often extremely conservative about that kind of thing.
|
# ? Dec 10, 2012 20:29 |
|
We interrupt this C++ horror to present:php:<? $fd = fopen("/var/boss/serv_log.txt", "w"); fwrite($fd, "log"); fclose($fd); // one hundred lines later (it is a procedural file) $fd = fopen("/var/boss/serv_log.txt", "w"); // no fclose, fwrite, anything. ?>
|
# ? Dec 10, 2012 20:47 |
|
rjmccall posted:DIGITAL Ah, so that's why code in the X server relies on this. Do you know why we couldn't get a "number of arguments passed to variadic functions" argument exposed? va_length? It has to be there for va_copy to work.
|
# ? Dec 10, 2012 21:24 |
|
Zamujasa posted:We interrupt this C++ horror to present: For anyone that doesn't get the horror, the w flag is "open this and truncate it before getting a lock," aka "I have no idea how to correctly perform file I/O" and/or "somebody kill the idiot that decided that flag was a good idea."
|
# ? Dec 10, 2012 21:29 |
|
I ran into this today while trying to work on a recently fired programmers only project.code:
|
# ? Dec 10, 2012 23:31 |
|
That one's common enough to get it's own name: http://en.wikipedia.org/wiki/Loop-switch_sequence
|
# ? Dec 10, 2012 23:36 |
|
Suspicious Dish posted:Do you know why we couldn't get a "number of arguments passed to variadic functions" argument exposed? va_length? It has to be there for va_copy to work. va_copy doesn't copy the actual arguments; it just copies the varargs iteration state. So in the traditional implementation where all arguments are on the stack and va_list is just a char*, it's literally just a pointer assignment. Basically I'm saying that you can't have a va_length because that is not, in fact, passed as part of any variadic conventions that I know of.
|
# ? Dec 11, 2012 00:02 |
|
I've actually seen loop-switch before in the wild in a sane context. It was an image filter and it did it to get around having a metric assload of function calls. Also regarding the hello world chat: I the only one who considers C++ streams a horror in the context of people learning to program?
|
# ? Dec 11, 2012 04:00 |
|
bucketmouse posted:I've actually seen loop-switch before in the wild in a sane context. It was an image filter and it did it to get around having a metric assload of function calls. How on earth is C++ code:
C++ code:
raminasi fucked around with this message at 04:37 on Dec 11, 2012 |
# ? Dec 11, 2012 04:15 |
|
it would be clearer if it was representing something like a state machine, but good languages give you better ways of expressing those anyway. Do not use loop-switch.
|
# ? Dec 11, 2012 04:23 |
|
Internet Janitor posted:it would be clearer if it was representing something like a state machine, but good languages give you better ways of expressing those anyway. Do not use loop-switch. Some of us actually have to write code where you have to implement stuff like duff's device for optimizations. If only every platform had compilers as good as x86...
|
# ? Dec 11, 2012 05:02 |
|
The case I was thinking of was vanilla C and, now that I think of it, very much a state machine.
|
# ? Dec 11, 2012 05:29 |
|
McGlockenshire posted:For anyone that doesn't get the horror, the w flag is "open this and truncate it before getting a lock," aka "I have no idea how to correctly perform file I/O" and/or "somebody kill the idiot that decided that flag was a good idea." Also the fact that the entirety of the log is literally the word "log". That wasn't a joke or a victim of anonimization, that's really all that's there.
|
# ? Dec 11, 2012 11:13 |
|
I assure you there was no point for the loop switch. Glad to know it has a name, it came out of a programmer with 15 years of experience.
|
# ? Dec 11, 2012 14:38 |
|
Internet Janitor posted:it would be clearer if it was representing something like a state machine, but good languages give you better ways of expressing those anyway. Do not use loop-switch. What superior alternatives are there to implementing a state machine to loop/switch/control-variable, and thinly veiled variations on this theme like loop/table-of-function-pointers/control-variable?
|
# ? Dec 11, 2012 15:24 |
|
Otto Skorzeny posted:What superior alternatives are there to implementing a state machine to loop/switch/control-variable, and thinly veiled variations on this theme like loop/table-of-function-pointers/control-variable? The one that comes immediately to mind is each state is a function, state transitions are a tail call. If you don't have tail call optimization you can use something like clojure's trampoline which is at least a bit nicer to use than a loop + external control variable.
|
# ? Dec 11, 2012 18:22 |
|
CCrew posted:I assure you there was no point for the loop switch. Glad to know it has a name, it came out of a programmer with 15 years of experience. What does it take to fire a programmer with 15 years of experience? Which straw broke that camel's back?
|
# ? Dec 11, 2012 18:33 |
|
You could argue that almost any FSM implementation will compile into the equivalent of either a nest of gotos or a loop-switch, but there are definitely better ways of specifying them. From the gamedev side of things, UnrealScript is slightly interesting, although it really provides Pushdown Automata rather than FSMs. GOOL had first-class FSM support in ways that could be added to Lisps. In Forth you can make a DSL which resembles a state transition table, which has the significant advantage over many other approaches that at a glance you can tell the set of transition rules is exhaustive: code:
Ragel to specify your FSM as a regular language.
|
# ? Dec 11, 2012 18:36 |
|
A loop switch sequence isn't the same as making a state machine because you're switching on the loop variable, not a state variable (well ok it's a trivial state machine that doesn't need a loop). Making a state machine with a loop is fine, implementing a known series of steps using a switch within a for loop isn't.
|
# ? Dec 11, 2012 18:37 |
|
bucketmouse posted:Also regarding the hello world chat: I the only one who considers C++ streams a horror in the context of people learning to program?
|
# ? Dec 11, 2012 18:45 |
One of these is definitely bad, the other is just kinda dumb:C++ code:
C++ code:
|
|
# ? Dec 11, 2012 18:57 |
|
Presto posted:I think they're a horror in any context. You're going to have to elaborate on that one.
|
# ? Dec 11, 2012 19:03 |
|
Presto posted:I think they're a horror in any context. C++ code:
C++ code:
|
# ? Dec 11, 2012 19:14 |
|
nielsm posted:
Isn't that just equivalent to: C++ code:
|
# ? Dec 11, 2012 19:17 |
Holy christ on a crackercode:
|
|
# ? Dec 11, 2012 19:21 |
|
ToxicFrog posted:The one that comes immediately to mind is each state is a function, state transitions are a tail call. I would rather build a richards controller or register fsm with 74-series logic than do this Internet Janitor posted:From the gamedev side of things, UnrealScript is slightly interesting, although it really provides Pushdown Automata rather than FSMs. Neat! Internet Janitor posted:In Forth you can make a DSL which resembles a state transition table, which has the significant advantage over many other approaches that at a glance you can tell the set of transition rules is exhaustive: Internet Janitor posted:
At work we've played around with tools that generate a table-of-function-pointers FSM from a visio-esque state diagram. So far they're either lovely or 5 figures per seat. At the end of the day, the downside to the 'classical' state machine implementation and some of the 'semi-classical' varieties is that it's somewhat more verbose than I'd like. Thankfully gcc will warn you if you've forgotten a case so long as your state variable is an enum, so at least one source of error is eliminated (the biggest source of error is still mis-specifying the transition table ).
|
# ? Dec 11, 2012 19:22 |
|
Otto Skorzeny posted:I would rather build a richards controller or register fsm with 74-series logic than do this
|
# ? Dec 11, 2012 19:24 |
ToxicFrog posted:Isn't that just equivalent to: As I mentioned, and you even quoted, not if you let the counter run from a non-multiple of 3 to possibly another non-multiple of 3. (In that case, you are rapidly entering regular state machine territory.)
|
|
# ? Dec 11, 2012 19:46 |
|
nielsm posted:As I mentioned, and you even quoted, not if you let the counter run from a non-multiple of 3 to possibly another non-multiple of 3. (In that case, you are rapidly entering regular state machine territory.) Yes, but as written it's not doing that and given that I'd call them both "definitely bad".
|
# ? Dec 11, 2012 19:50 |
|
PrBacterio posted:The same goes for C++ string handling, where it isn't even possible to convert a number into a string with standard C++ functions except by using a string stream. What ought to be a single line of code C++11 to the rescue C++ code:
|
# ? Dec 11, 2012 20:21 |
|
Jerry SanDisky posted:C++11 to the rescue
|
# ? Dec 11, 2012 20:43 |
|
PrBacterio posted:Ah, so they've finally fixed that? Good. Now just to see how long it takes for compilers to arrive that support and correctly implement the new standard ... http://msdn.microsoft.com/en-us/library/vstudio/ee404875(v=vs.100).aspx
|
# ? Dec 11, 2012 21:09 |
|
The current MSVC implementation is based on an older version of the standard that only specified those 3 overloads. I believe GCC supports all 9.
|
# ? Dec 11, 2012 21:14 |
|
|
# ? Jun 7, 2024 12:19 |
|
Jerry SanDisky posted:The current MSVC implementation is based on an older version of the standard that only specified those 3 overloads. I believe GCC supports all 9. MS doesn't do all the overloads in math.h either so at least its consistent.
|
# ? Dec 11, 2012 21:27 |