4 ms·
>Are the arguments to memcpy in the order of source, destination, length; or are they destination, source, length? Is strstr haystack, needle; or is it needle,
by sharpercoder 10y ago
>Are the arguments to memcpy in the order of source, destination, length; or are they destination, source, length? Is strstr haystack, needle; or is it needle, haystack? Many individuals develop a habit of consulting references (such as system manuals) as soon as the question comes up.
I've always found this particular problem solveable by allowing programming languages having syntax in the form of
public void CopyFrom(int address)To(int address)OfSize(long size) { // impl }
instead of
Copy(int fromAddress, int toAddress, long size)
Are there good reasons why languages haven't adopted this syntactic nicety?
- seanwilson 10y agoSurely having your IDE bring up the argument names during autocomplete solves this?
- fit2rule 10y agoDependence-on-IDE is a liability. Ability to find and read the docs: an asset.
- seanwilson 10y ago> Dependence-on-IDE is a liability. Why? Use the best tool for the job. > Ability to find and read the docs: an asset. Read the docs + use a good IDE.
- edejong 10y agoYes, I don't see this point either. A 'man 3 stpncpy' or an alt-space seems rather similar to me. Actually, with the 'man 3 stpncpy' we cannot be sure the results will align with the target platform. Everyone uses IDEs, whether it is Emacs, Vim (with plugins), IntelliJ, Eclipse, Atom, Xcode doesn't matter. Yes, I also use whiteboards, A4's, a notepad, mindmaps (Freemind), post-its and more. The creative parts of SE, such as architecture and design, do not blossom behind a computer.
- seanwilson 10y agoYou don't think the IDE automatically bringing up the documentation for the function arguments is more efficient here than typing terminal commands for each function you're using? I don't understand why people insist on using bare bones text editors when IDEs with more automation exist.
- edejong 10y agoYes, perhaps I was not clear. I do think an IDE is more efficient. Actually, I believe a modern IDE is barely scratching the surface of what could be possible. I am one of the lunatics who believe in editing directly on the AST, forgoing the filesystem and working on one shared merkle-tree-like database with function signatures as the primary entry point for search.
- xgbi 10y agoObj-C uses this. C, on the other end, allows prototypes to be defined as: void* memcpy(void*, void* size_t) // no argument name Which is the worse IMHO. The autocomplete cannot event tell you which is which..
- nostrademons 10y agoAnd Swift, and Smalltalk. 3 generations of that one family. It leads to very verbose code, which is perhaps why it hasn't caught on in other languages. It also can be surprisingly clumsy when a method is called from multiple call sites (which may apply it to different parameters in subtly different contexts, which can make the original phrasing awkward), or when a method is passed around as a first-class value.
- eriknstr 10y agoPersonally I use prototype definition without argument names because when I change the name of an argument in the C file I don't have to go to the header file and change the prototype. The code I work with in C is generally small enough that I have all the relevant C files open in different windows while working on the code, and furthermore because my programs are quite small I don't use autocompletion. What I do have however is simple completion that is not sensitive to the context but which will complete a word once I've typed part of it. This way I can have meaningful names for things without having to spend too much time when I write them.
- deleted 10y ago[deleted]
- realharo 10y agoWhat's the point of having two names for each parameter instead of just one? Just allow using named parameters in calls, this Objective-C-ism is ugly as hell.
- eriknstr 10y agoSome JavaScript frameworks use method chaining in-order to give you something very similar to what you are talking about. $('#my-div').css('background', 'blue').height(100).fadeIn(200); Personally I don't use JavaScript frameworks very often so I'm still not very used to this. The first time I encountered it I didn't like it at all but now I think it's ok. Something else that also enables code similar to what you are talking about is using named arguments in Python. somewhat_similar(barfoo=thing, using_fnord=mahjong, baz_provider=xyzzy, quux_helper=fob) but personally the way I use named arguments is only for the select few arguments that will sometimes appear and sometimes not in combinations that make the ordering alone insufficient to handle this. In my code regardless of language, I generally try to order the argument with target as the first argument, source(s) second and additional arguments following that. Somewhat related to these things is also the fact that I use constants and enums for values rather than "true" and "false" when calling functions that take booleans as arguments. As I noted in another comment I generally work on small programs at a time. This makes it generally ok for me to remember or to find the arguments taken by a function even though I don't have autocompletion.
- eriknstr 10y agoI have a stray dash in the above comment. Too late to edit now. Where I said "in-order" I meant to say "in order".
- Sean1708 10y agoHow would you call your function and how would you refer to the arguments inside the function?