4 ms·
https://doc.rust-lang.org/book/ch12-04-testing-the-librarys-functionality.html https://doc.rust-lang.org/book/ch12-04-testing-the-librarys-... pub fn search<
by hello_moto 7y ago
https://doc.rust-lang.org/book/ch12-04-testing-the-librarys-functionality.html https://doc.rust-lang.org/book/ch12-04-testing-the-librarys-...
pub fn search<'a>(query: &str, contents: &'a str) -> Vec<&'a str> {
vec![]
}
- steveklabnik 7y agoYou didn't elaborate on exactly what you find esoteric about all of this, but here's all the non [a-zA-Z] characters, what they do, and how they relate to my sibling comment about objections: <> for generics. Point 3. 'a for a lifetime. Point 2. () , and {} for function syntax. Point 3. pattern: type for arguments. This is in a few different languages, and doesn't fit into my below points, but the paragraph I made after the point. & for references, point 3. -> for the return type of functions. In the paragraph after. ! to indicate that vec! is a macro. This is pretty unique, actually. Ruby does let you use ! in function names, but that's not really the same thing. [] is used to invoke vec! similarly to how you index anything else, that is, this creates an empty vec, like [] would create an empty array. This is sorta point 3 and the final paragraph. None of this is to say that you're wrong about this; I think it just really demonstrates how hard it is to please people with syntax. None of this is unique to Rust, but the combination of influences is.
- hello_moto 7y ago> I think it just really demonstrates how hard it is to please people with syntax There's no silver bullet just like anything else. It's a matter of preference. Generics is fine (exist in C++ and Java). Although I dislike crazy generics <T<S>> but that could be design problem. <'a> (yeah technically it's just the 'a. "->" non-alphabet, I came from C family (C/C++/Java) so return type stated earlier as part as the whole long-train of ceremonial stuff alongside the modifier (public static int myMethod) Pointers and Reference: not my cup of tea but I understand it's important for system language. Others can argue its importance for "business apps" (or web-apps) but I never need pointers and references so _shrug_. semi colon after input parameter: query: &str vs string query contents: &'a str Vec<&'searching str> <--- the fact that now you can combine these non-alphabet stuff together => "&'a". vec![] => exclamation mark squeezed between what appears to be a keyword "vec" and an array syntax Again, don't get to riled up. I just personally don't enjoy reading syntax like this.
- sbov 7y agoGiven their requirements, I'm not sure they could figure out a way to do this that would satisfy you. The syntax choices Rust made don't seem any stranger than e.g. Go. Rust just has more concepts because of what it's trying to accomplish.
- hello_moto 7y agoOf course, of course. I'm not asking them to satisfy me. I'm not in the field of system programming/embedded software. I'm more in app-development.
- asdkhadsj 7y agoIt's funny, ~10 (maybe 15 now? yikes) years ago I was totally in a similar boat. Hardcore Python, felt that syntax was gross and brackets were dumb, etc (not that this is how you feel). Over the years I have just grown repeatedly to love static and typed. The larger my code bases the more it (dynamic features) always seemed to be something that caused me trouble. Typed languages felt bad for prototyping, but as time went on that argument of mine just didn't seem to hold water. I definitely don't feel that way now. And, while I do like Rust's syntax, and have grown strangely fond to the syntax coined "The Turbofish" ::<>, I just haven't seen a typed language that can do what Rust can with a vastly more simplified syntax (ie, Python). I imagine it's not possible, but I'm not making claims here - just thinking out loud. Of course, Haskell and friends might be near that camp, but arguably even if the language is as powerful I'd they're too different to qualify for my statement. Anyway, not trying to convince you of anything. Just thinking out loud. Carry on friend :)
- hello_moto 7y ago> felt that syntax was gross and brackets were dumb This is how I feel when I saw any languages that utilize special characters. It is shorter, I give you that, but that shortness is taxing my brain. No, I'm not asking for convincing as I mentioned I'm not the target audience of Rust (system programming, OS, etc). Ironically at college my specialization was System Programming, OS, and Database. Pretty much infra stuff that Rust serves well :). Not sure what happened along the way that changed my mind.
- Keyframe 7y agoSteve, combination of all of those resembles Vogon poetry that's often found in modern c++. It's what it looks like to a newcomer, that's undeniable. Having said that, it does tend to go away as you start using it. Almost.
- agumonkey 7y agoMore than syntax, methinks it's semantics and culture. For those who went off road toward ML, Lisps, Prolog etc, syntax becomes a mere detail. We care more about what the linguistic constructs give us, whatever the clothing. But for others, it's a god damn slap in the face.
- hello_moto 7y agoThis is one way to view the state/situation in our field. Those who build data-pipeline, ML, processing big-data, they love constructs that can help them achieve their goal faster. Those constructs are essentially processing collection type of constructs: predicates(), forEach(), map(), reduce(), transform(), filter(), etc. Those who writes business-apps tend to favor OOP because they need to map business domains.
- anticensor 7y agopub fn search<'searching>(query: &str, contents: &'searching str) -> Vec<&'searching str> { vec![] } Give your lifetimes meaningful names.
- empath75 7y agoThat’s interesting — I haven’t seen any code that does this. Do you have more fleshed out examples on github to share?
- steveklabnik 7y agoWe had discussions about this prior to 1.0, and some people do write code this way, but in general, you’re only using lifetimes in more complex code, and doing this makes it even more verbose. It does sometimes help, though. I personally prefer the ‘a version in this case for this reason, it’s actually harder for me to understand. YMMV.
- 0815test 7y agoIn a BASIC- or COBOL-like language, that would be something roughly like: PUBLIC FUNCTION Search \ GIVEN REGION Searching \ TAKING Query: SHARED Str, \ Contents: SHARED Str REGION Searching \ GIVING Vector OF SHARED Str REGION Searching IS TAKE Vector!Empty END FUNCTION. It might look like an improvement if you're seeing Rust-like code for the first time ever, but it very much isn't one in the longer run! Even the final version of that function might be somewhat tedious to write and review, to say nothing of something even slightly longer than that!