|
raminasi posted:see, i like this (but only if you have nested functions) no he forbids those lol
|
# ? Jun 29, 2016 22:36 |
|
|
# ? Jun 12, 2024 02:53 |
|
see that style is okay in haskell when you can add a where removeButts = filterNot isAss . filterNot isButt . filterNot isToushie to the end of the function but I really dislike defining nested functions before the main logic of the function which you have to do in most iterative langs
|
# ? Jun 29, 2016 22:37 |
|
gonadic io posted:ask me about having a coworker that obsessively moves half of the lines of code in any given method into a 1-line 1-use helper function for each one. it's not like they're long or complicated lines but there are so many functions like ask me about having a coworker who refactors this: code:
code:
he's a massively petulant rear end in a top hat though so it's not unexpected when he submits a pull request that consists of aggressively refactoring only this kind of thing
|
# ? Jun 29, 2016 23:18 |
|
Blinkz0rz posted:ask me about having a coworker who refactors this: oh i didn't mean takes perfectly working code and spends company time changing it for no benefit, that's a whole other level of obsessive. mine just always writes it like that and argues in code reviews for it
|
# ? Jun 29, 2016 23:40 |
I thinkPython code:
|
|
# ? Jun 29, 2016 23:54 |
|
VikingofRock posted:
|
# ? Jun 30, 2016 00:19 |
|
comments lie
|
# ? Jun 30, 2016 00:30 |
|
also:code:
|
# ? Jun 30, 2016 00:31 |
|
making a helper class for a complex operation is really a trick that people don't do enough
|
# ? Jun 30, 2016 00:51 |
JawnV6 posted:??? The comments help show what's going on, but with a large enough function it's still hard to follow because there's so much you mentally have to keep track of. Also too much scrolling! tef posted:also: The inline functions are good, but not every language has them and you still gotta scroll past them to get to the main part of the function. Passing the state through self can work, if process() logically lends itself to being a member of Foo or whatever, but that's not always the case. I'm not arguing that what I posted is always right. Just that it's not that crazy of a thing to do and it can make reading things easier in some circumstances. Just make sure you don't export the helper functions so you don't clutter things up too much.
|
|
# ? Jun 30, 2016 00:54 |
|
tef posted:but uh you could also just have a goddam class and pass the state around via self like a normal person rather than hocking a bunch of args around by hand
|
# ? Jun 30, 2016 01:05 |
|
Dr Monkeysee posted:comments lie so do function names
|
# ? Jun 30, 2016 01:54 |
|
Gnu c lets you define nested functions Except the emitted code writes and jumps to executable code on the stack, which is the computer security equivalent of trying to board an aircraft with a gallon of nitroglycerin in your carry on
|
# ? Jun 30, 2016 01:54 |
|
i generally prefer the single large function, although i wish more languages supported anonymous blocks with their own scope (or that more people used them). the only problem i really have with the one large function is that many variables have lifetimes exceeding their use. putting them in blocks helps clarify lifetime, and serves as a good way to group sections of code.
|
# ? Jun 30, 2016 02:05 |
|
when it comes down to splitting a function out by length, odds are it isn't worth it. doing that trick inevitably ends up with functions with 26 arguments, or methods with 26 inner variables. the hard part is not the lines of code in the function, the hard part is the amount of local state and how it interacts. length of function is a good proxy, but number of local variables or arguments may be more helpful. like, i enjoy reading code that's narratively structured: the design and layout of features considers someone reading the file from top to bottom sure, lifting into an object can be worth it if you need to express the logic but not the control flow in the same way: result = AHardThing(setup).step_one(options).step_three(), but your consumers gain nothing from a bunch of helper functions. i still use them, but it's often because the amount of error handling or boilerplate is sufficient that i want to hide it away from the top-level control flow/process, on the other hand i've written monoliths of functions, but it turns out bootstrap code is always going to be ugly so make it read from top to bottom. you aren't always really cleaning things up by using objects or closures, sometimes you're making poo poo more awkward to engineer. breaking things out into functions is good when you can read that function and it has very little shared state, and when you call it, you don't need to refer to the implementation. and some functions are just going to be long. i've also seen arguments about it being easier to test but i'm not convinced tightly coupling your tests into implementation specifics works out in the long term
|
# ? Jun 30, 2016 02:10 |
|
helper functions in compilers often need to be recursive, and they often need to maintain at least 2-3 pieces of context, and they often accumulate extra parameters and results. extracting out to a class is usually the right thing to do, especially once you find yourself writing mutually-recursive functions but here i will disobey the iron law of programming punditry and admit that my experience may not be representative
|
# ? Jun 30, 2016 02:38 |
|
Or how about a struct that carries the parameters? No need to get object orientated.
|
# ? Jun 30, 2016 06:40 |
|
Blinkz0rz posted:ask me about having a coworker who refactors this: reformatting code isn't refactoring
|
# ? Jun 30, 2016 20:25 |
|
also you are both equally bad for caring at all about the difference
|
# ? Jun 30, 2016 20:48 |
|
i think blinkzorz doesnt care so much about the difference but that the other guy cares so much that he submits pull requests changing just that
|
# ? Jun 30, 2016 20:56 |
|
Thermopyle posted:i think blinkzorz doesnt care so much about the difference but that the other guy cares so much that he submits pull requests changing just that this
|
# ? Jun 30, 2016 23:07 |
|
rjmccall posted:making a helper class for a complex operation is really a trick that people don't do enough a closure is a poor man's object nested functions w/ closures are generally the right abstraction when you want to modularize heavily related code inside a function. unfortunately most languages provide poor support for this. unless you have a bunch of necessarily intertwined, mutable local state, a function exceeding 20 statements/lines/whatever is probably (not always) a bad function it's probably hard to have that much necessary intertwined mutable local state inside a single function unless you're creating a performant data structure or something like that comedyblissoption fucked around with this message at 23:44 on Jun 30, 2016 |
# ? Jun 30, 2016 23:40 |
|
comedyblissoption posted:an object is a poor man's closure Objects are only closures when they have virtual functions.
|
# ? Jul 1, 2016 05:47 |
|
tef posted:and some functions are just going to be long. loving this. also if you test the equality of two things that have 10 member variable then yes, the function is going to have a high cyclomatic complexity number. it doesn't make the function complex to understand.
|
# ? Jul 1, 2016 07:50 |
|
Wheany posted:loving this. get a better language? ¯\_(ツ)_/¯ code:
|
# ? Jul 1, 2016 08:00 |
|
b0lt posted:get a better language? ¯\_(ツ)_/¯ Java code:
|
# ? Jul 1, 2016 08:26 |
Aren't there a bunch of ifs ands and buts about using std::tie? Like it doesn't work with references or something?
|
|
# ? Jul 1, 2016 08:35 |
Oh wait I think it just doesn't work with r-values. Not sure why you would want to do that anyways though.
|
|
# ? Jul 1, 2016 08:38 |
|
Wheany posted:
Get an even better language? code:
|
# ? Jul 1, 2016 08:39 |
|
i apologize for ever using branches.
|
# ? Jul 1, 2016 08:41 |
|
Python code:
JawnV6 posted:??? this too is perfectly acceptable if you have a sufficiently smart ... operator
|
# ? Jul 1, 2016 10:28 |
|
i found http://blog.rust-lang.org/2016/06/30/State-of-Rust-Survey-2016.html and it has this part "Another big piece of the Rust development experience is using the Cargo tool." so i googled "rust cargo" and found https://crates.io/ "The Rust community’s crate host" "Instantly publish your crates and install them. Use the API to interact and find out more information about available crates. Become a contributor and enhance the site with your work." i still have no idea what it is. (i assume it's a package/dependency manager of some sort and crates are the packages/libraries) i loving hate websites for tools and frameworks that acty coy or try to be funny about what they are (it's like monkey cheese bacon for your narwhal to all the code ninjas out there!!!! LOL)
|
# ? Jul 1, 2016 13:30 |
|
crates are libraries cargo is the dependency/package manager for crates. it also provides a framework for building projects and running tests from a CLI. https://doc.rust-lang.org/book/crates-and-modules.html you are right that it is dumb they decided to invent the new term crate i suggest looking past it and forgiving the rust community b/c rust is a very good language
|
# ? Jul 1, 2016 14:16 |
|
they can call them bags if they want to, just tell me what your web page is about. compare that to https://www.rust-lang.org/ "Rust is a systems programming language that runs blazingly fast, prevents segfaults, and guarantees thread safety." with a list of features underneath. that is close to perfect.
|
# ? Jul 1, 2016 14:32 |
|
to be fair the rust docs explain what cargo is and how to use it right in their getting started page https://doc.rust-lang.org/book/getting-started.html#hello-cargo but yah that website could use an explanation somewhere and how to use cargo youre right even if it's literally just a link to the above document
|
# ? Jul 1, 2016 14:46 |
|
hey guys containers are hot right now lets get in on that somehow
|
# ? Jul 1, 2016 14:56 |
|
Nice of them to reuse half of the term "cargo cult," though.
|
# ? Jul 1, 2016 15:01 |
|
MALE SHOEGAZE posted:hey guys containers are hot right now lets get in on that somehow what's rust's time to crate?
|
# ? Jul 1, 2016 15:04 |
|
gonadic io posted:what's rust's time to crate? heh
|
# ? Jul 2, 2016 15:34 |
|
|
# ? Jun 12, 2024 02:53 |
|
|
# ? Jul 10, 2016 13:19 |