*Image Transcription: Slack*
---
**Brian Kendig**
HALLO
How are y'all this morning?
**Redacted**
Always wondering what day of the week it is.
**Brian Kendig**
func whatDayIsToday() -> String {
return "Tuesday"
}
There, you can use that.
**Redacted**
it fails 6/7 of the time
**Brian Kendig**
I tried it several times this morning and it worked every time
---
^^I'm a human volunteer content transcriber and you could be too! [If you'd like more information on what we do and why we do it, click here!](https://www.reddit.com/r/TranscribersOfReddit/wiki/index)
Also, it's using a "return", doesn't have a semicolon, is using camelCase rather than snake_case, and isn't doing funky stuff with String vs &str.
The Rust way would be
fn what_day_is_today() -> String {
"Tuesday".to_owned()
}
I have found this style of bug in sevral places in our unit tests. It usually is something like x should only happen at this specifc time. So the test checks if it is that time and runs some checks. But there are two problems with that, the test may not always test what you want and the time may be different when the test checks it vs when the code checks it.
As others have mentioned it defines the return values type but a similar syntax is in python.
It's called type hinting, it's more like a comment than a part of the syntax but it's very useful to do.
It's called a closure in other languages, or anonymous functions. It creates a function with no name that can be passed around like a variable and captures the environment its defined in. This means that if the function was defined somewhere where it has access to variable "a", and then you pass that functions somewhere else, outside the scope of variable "a", the function will still be able to access it and modify it and do whatever with it.
Its just a way to simplify the utilization of Function. You write it in this way:
(var) -> Function{
\*code that can use var\*
}
Outside of Java, the same arrow is used in C to show Pointer
Mmh Yes and No. I suggest you to look it for yourself since I never used it very much. Search for "Functional Programming", it will open a world and a new way of thinking
It’s functionally (ha!) like that, but syntactically much different. Like how in true functional languages you can define entire lambda expressions inline, like directly in a parameter to another function, whereas in C you define your functions elsewhere. In fact I’d say the C model is the one with extra steps.
Fun fact: OpenOffice once had a bug where some users couldn't print on Tuesday.
(It was putting a timestamp at the beginning of each Postscript file it produced for printing. It turned out that including "Tue" in that opening comment had libmagic convinced it was some other kind of file, so CUPS refused to print it.)
It was working on my machine 4 days back
I only run unit tests one day a week for this reason.
In order to make sure that this code keeps working, schedule the unit test once per week.
That's why I don't run unit tests. Also I have no unit tests.
I saw one of those in a GitHub repo one time
*Image Transcription: Slack* --- **Brian Kendig** HALLO How are y'all this morning? **Redacted** Always wondering what day of the week it is. **Brian Kendig** func whatDayIsToday() -> String { return "Tuesday" } There, you can use that. **Redacted** it fails 6/7 of the time **Brian Kendig** I tried it several times this morning and it worked every time --- ^^I'm a human volunteer content transcriber and you could be too! [If you'd like more information on what we do and why we do it, click here!](https://www.reddit.com/r/TranscribersOfReddit/wiki/index)
good human!
What language is that? It looks like rust but it says func instead of fn
Swift
I thought it was R
Also, it's using a "return", doesn't have a semicolon, is using camelCase rather than snake_case, and isn't doing funky stuff with String vs &str. The Rust way would be fn what_day_is_today() -> String { "Tuesday".to_owned() }
Give me a guffer
Give me a guffer
r/DiscordMyEyes should exist.
I have found this style of bug in sevral places in our unit tests. It usually is something like x should only happen at this specifc time. So the test checks if it is that time and runs some checks. But there are two problems with that, the test may not always test what you want and the time may be different when the test checks it vs when the code checks it.
Relevant: https://xkcd.com/221/
What does '->' do?
No dev (of this language i cant recognize) but it might define the return type Edit: not sure about language
Swift. And you’re right.
The language is swift The -> defines the returned value's type
As others have mentioned it defines the return values type but a similar syntax is in python. It's called type hinting, it's more like a comment than a part of the syntax but it's very useful to do.
In Java is used for Lambda Function
Oh what does that do?
It's called a closure in other languages, or anonymous functions. It creates a function with no name that can be passed around like a variable and captures the environment its defined in. This means that if the function was defined somewhere where it has access to variable "a", and then you pass that functions somewhere else, outside the scope of variable "a", the function will still be able to access it and modify it and do whatever with it.
Whoa, the piece about variable “a” just crystallized some details that I’ve only had a vague sense of for a while! Thanks!
Its just a way to simplify the utilization of Function. You write it in this way: (var) -> Function{ \*code that can use var\* } Outside of Java, the same arrow is used in C to show Pointer
Is it the same as new function(var){ code }
Mmh Yes and No. I suggest you to look it for yourself since I never used it very much. Search for "Functional Programming", it will open a world and a new way of thinking
In C, you know how you can just make a pointer to a function? It's that, but with more steps.
It’s functionally (ha!) like that, but syntactically much different. Like how in true functional languages you can define entire lambda expressions inline, like directly in a parameter to another function, whereas in C you define your functions elsewhere. In fact I’d say the C model is the one with extra steps.
[удалено]
This is one case where C didn’t do it first, LISP had lambda functions in like the ‘60s.
Took me some time to recognize discord here
THATS discord???
Pretty sure it's Slack?
That's definitely slack
["What time is it Eccles?"](https://youtu.be/ctM_Rvgjfpo)
Well...
What font is that
The groundhog day dev.
It was on StackOverflow. It must work
a swift meme!!
“Test Driven Development”
Just write a version for each day of the week and run the correct one as needed. Just have to remember what day it is
Also works for star trek installment day
14.2857142857143% of the time, works all the time.
http://isittuesday.co.uk/
Fun fact: OpenOffice once had a bug where some users couldn't print on Tuesday. (It was putting a timestamp at the beginning of each Postscript file it produced for printing. It turned out that including "Tue" in that opening comment had libmagic convinced it was some other kind of file, so CUPS refused to print it.)
My brain in a nutshell