René's URL Explorer Experiment


Title: Use strong typing instead of ruby-like `1.seconds` · Issue #4 · radex/SwiftyTimer · GitHub

Open Graph Title: Use strong typing instead of ruby-like `1.seconds` · Issue #4 · radex/SwiftyTimer

X Title: Use strong typing instead of ruby-like `1.seconds` · Issue #4 · radex/SwiftyTimer

Description: Extending Int and Double with properties second, seconds, minute, etc. seems like a rather bad idea. There's two problems with this: Anyone using your code in a project with other 3rd-party code that wants to do something similar will ha...

Open Graph Description: Extending Int and Double with properties second, seconds, minute, etc. seems like a rather bad idea. There's two problems with this: Anyone using your code in a project with other 3rd-party code th...

X Description: Extending Int and Double with properties second, seconds, minute, etc. seems like a rather bad idea. There's two problems with this: Anyone using your code in a project with other 3rd-party cod...

Opengraph URL: https://github.com/radex/SwiftyTimer/issues/4

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Use strong typing instead of ruby-like `1.seconds`","articleBody":"Extending `Int` and `Double` with properties `second`, `seconds`, `minute`, etc. seems like a rather bad idea. There's two problems with this:\n1. Anyone using your code in a project with other 3rd-party code that wants to do something similar will have a compile-time naming collision, making it impossible to use either one.\n2. It's weakly-typed. You're still taking `NSTimeInterval` as your actual time type, and all it takes is for someone to accidentally leave off the `.minutes` and they'll get the wrong time. This isn't a huge issue, as `NSTimeInterval` is used everywhere to mean seconds and people are used to it, but we can still do better.\n\nThe better approach is to use an actual `Duration` type that requires the user to type the unit as part of the constructor. With the ruby-like approach you can just say `NSTimer.after(1) { ... }` but with a proper strong type there's no way to do this. I'd suggest something like\n\n``` swift\n/// A type that represents a given duration.\npublic struct Duration: Comparable, Hashable, Printable, DebugPrintable {\n    /// The time interval of the `Duration`, in seconds.\n    let seconds: NSTimeInterval\n    /// The time interval of the `Duration`, in minutes.\n    var minutes: NSTimeInterval {\n        return seconds / 60\n    }\n    /// The time interval of the `Duration`, in hours.\n    var hours: NSTimeInterval {\n        return seconds / 3600\n    }\n    /// The time interval of the `Duration`, in milliseconds.\n    /// Sub-millisecond values are truncated.\n    var milliseconds: Int64 {\n        return Int64(seconds * 1_000)\n    }\n    /// The time interval of the `Duration`, in microseconds.\n    /// Sub-microsecond values are truncated.\n    var microseconds: Int64 {\n        return Int64(seconds * 1_000_000)\n    }\n    /// The time interval of the `Duration`, in nanoseconds.\n    var nanoseconds: Int64 {\n        return Int64(seconds * 1_000_000_000)\n    }\n\n    /// Construct a `Duration` for a given number of seconds.\n    public init(seconds: NSTimeInterval) {\n        self.seconds = seconds\n    }\n    /// Construct a `Duration` for a given number of minutes.\n    public init(minutes: NSTimeInterval) {\n        self.init(seconds: minutes * 60)\n    }\n    /// Construct a `Duration` for a given number of hours.\n    public init(hours: NSTimeInterval) {\n        self.init(seconds: hours * 3600)\n    }\n    /// Construct a `Duration` for a given number of milliseconds.\n    // Use Int64 because milliseconds are generally not floating-point\n    // values\n    public init(milliseconds: Int64) {\n        self.init(seconds: NSTimeInterval(milliseconds) / 1_000)\n    }\n    /// Construct a `Duration` for a given number of microseconds.\n    public init(microseconds: Int64) {\n        self.init(seconds: NSTimeInterval(microseconds) / 1_000_000)\n    }\n    /// Constructs a `Duration` for a given number of nanoseconds.\n    // How much tolerance does a timer actually support?\n    public init(nanoseconds: Int64) {\n        self.init(seconds: NSTimeInterval(nanoseconds) / 1_000_000_000)\n    }\n\n    public var description: String {\n        // TODO: Display human-readable string with multiple units\n        return toString(seconds)\n    }\n\n    public var debugDescription: String {\n        return \"Duration(\\(seconds))\"\n    }\n\n    public var hashValue: Int {\n        return seconds.hashValue\n    }\n}\n\npublic func +(lhs: Duration, rhs: Duration) -\u003e Duration {\n    return Duration(seconds: lhs.seconds + rhs.seconds)\n}\npublic func -(lhs: Duration, rhs: Duration) -\u003e Duration {\n    return Duration(seconds: lhs.seconds - rhs.seconds)\n}\n// NB: Don't implement multiplication/division, that doesn't make any sense for\n// durations. As such, we don't conform to IntegerArithmeticType either.\npublic func \u003c(lhs: Duration, rhs: Duration) -\u003e Bool {\n    return lhs.seconds \u003c rhs.seconds\n}\npublic func ==(lhs: Duration, rhs: Duration) -\u003e Bool {\n    return lhs.seconds == rhs.seconds\n}\n```\n\nThis way you can then say `NSTimer.after(Duration(seconds: 1)) { ... }`. You could also experiment with replacing all those initializers with static functions instead (e.g. `static func seconds(seconds: NSTimeInterval)`) so that way you can say `NSTimer.after(.seconds(1)) { ... }`.\n","author":{"url":"https://github.com/lilyball","@type":"Person","name":"lilyball"},"datePublished":"2015-05-11T21:47:10.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":8},"url":"https://github.com/4/SwiftyTimer/issues/4"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:024b4385-85d5-32fa-3e1d-36a2db28996f
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idCD3A:21F2BE:501231:71E287:696A0D59
html-safe-nonce48f2aa51ab9fe8004b7d8e5bd6dae28405e2906355090224a42c7bea01c34080
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDRDNBOjIxRjJCRTo1MDEyMzE6NzFFMjg3OjY5NkEwRDU5IiwidmlzaXRvcl9pZCI6IjkwMTU2NDU4ODM5NTk5MDM2MSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac9d80f59e4e8fbac9b60247992a755393c77c3de79ef6fb9baa1556abcf922dc8
hovercard-subject-tagissue:75370019
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/radex/SwiftyTimer/4/issue_layout
twitter:imagehttps://opengraph.githubassets.com/004847de2a9e7c90ad50f1d5c6ec9929500b91871ab05953d28d28198f415bd1/radex/SwiftyTimer/issues/4
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/004847de2a9e7c90ad50f1d5c6ec9929500b91871ab05953d28d28198f415bd1/radex/SwiftyTimer/issues/4
og:image:altExtending Int and Double with properties second, seconds, minute, etc. seems like a rather bad idea. There's two problems with this: Anyone using your code in a project with other 3rd-party code th...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamelilyball
hostnamegithub.com
expected-hostnamegithub.com
None699227a00bbb7fe1eec276d2ae1c3a93068bc5ba483bd9dc4b2a27a8f4f2f595
turbo-cache-controlno-preview
go-importgithub.com/radex/SwiftyTimer git https://github.com/radex/SwiftyTimer.git
octolytics-dimension-user_id183747
octolytics-dimension-user_loginradex
octolytics-dimension-repository_id35327084
octolytics-dimension-repository_nworadex/SwiftyTimer
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id35327084
octolytics-dimension-repository_network_root_nworadex/SwiftyTimer
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release7266b2d935baa1c6474b16dd9feaa5ca30607261
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/radex/SwiftyTimer/issues/4#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fradex%2FSwiftyTimer%2Fissues%2F4
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub SparkBuild and deploy intelligent appshttps://github.com/features/spark
GitHub ModelsManage and compare promptshttps://github.com/features/models
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
GitHub SponsorsFund open source developershttps://github.com/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/accelerator
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fradex%2FSwiftyTimer%2Fissues%2F4
Sign up https://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=radex%2FSwiftyTimer
Reloadhttps://github.com/radex/SwiftyTimer/issues/4
Reloadhttps://github.com/radex/SwiftyTimer/issues/4
Reloadhttps://github.com/radex/SwiftyTimer/issues/4
radex https://github.com/radex
SwiftyTimerhttps://github.com/radex/SwiftyTimer
Notifications https://github.com/login?return_to=%2Fradex%2FSwiftyTimer
Fork 136 https://github.com/login?return_to=%2Fradex%2FSwiftyTimer
Star 1.2k https://github.com/login?return_to=%2Fradex%2FSwiftyTimer
Code https://github.com/radex/SwiftyTimer
Issues 6 https://github.com/radex/SwiftyTimer/issues
Pull requests 4 https://github.com/radex/SwiftyTimer/pulls
Actions https://github.com/radex/SwiftyTimer/actions
Projects 0 https://github.com/radex/SwiftyTimer/projects
Security Uh oh! There was an error while loading. Please reload this page. https://github.com/radex/SwiftyTimer/security
Please reload this pagehttps://github.com/radex/SwiftyTimer/issues/4
Insights https://github.com/radex/SwiftyTimer/pulse
Code https://github.com/radex/SwiftyTimer
Issues https://github.com/radex/SwiftyTimer/issues
Pull requests https://github.com/radex/SwiftyTimer/pulls
Actions https://github.com/radex/SwiftyTimer/actions
Projects https://github.com/radex/SwiftyTimer/projects
Security https://github.com/radex/SwiftyTimer/security
Insights https://github.com/radex/SwiftyTimer/pulse
New issuehttps://github.com/login?return_to=https://github.com/radex/SwiftyTimer/issues/4
New issuehttps://github.com/login?return_to=https://github.com/radex/SwiftyTimer/issues/4
Use strong typing instead of ruby-like 1.secondshttps://github.com/radex/SwiftyTimer/issues/4#top
https://github.com/lilyball
https://github.com/lilyball
lilyballhttps://github.com/lilyball
on May 11, 2015https://github.com/radex/SwiftyTimer/issues/4#issue-75370019
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.