Skip to content

Add practice exercise: space-age - #107

Merged
IsaacG merged 5 commits into
exercism:mainfrom
jimmytty:space-age
Aug 6, 2025
Merged

Add practice exercise: space-age#107
IsaacG merged 5 commits into
exercism:mainfrom
jimmytty:space-age

Conversation

@jimmytty

@jimmytty jimmytty commented Aug 5, 2025

Copy link
Copy Markdown
Contributor
  • difficulty: 2 (easy).
  • used json object for result (keys: age and error).
  • added instructions.append.md.

@IsaacG

IsaacG commented Aug 5, 2025

Copy link
Copy Markdown
Member

@exercism/sqlite Thoughts on "easy" with a JSON object? Or, thoughts on using a JSON object vs a simple(r) output?

Comment thread exercises/practice/space-age/.docs/instructions.append.md Outdated
@@ -0,0 +1,29 @@
DROP TABLE IF EXISTS tmp;
CREATE TEMPORARY TABLE tmp (
p TEXT UNIQUE NOT NULL,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we use more descriptive names?

Comment on lines +16 to +29
UPDATE "space-age"
SET result = JSON_OBJECT('error', 'not a planet')
WHERE NOT EXISTS (SELECT 1 FROM tmp WHERE p = planet)
;

UPDATE "space-age"
SET result = JSON_OBJECT(
'age',
ROUND("space-age".seconds / 31557600.0 / tmp.op, 2)
)
FROM tmp
WHERE "space-age".planet = tmp.p
AND "space-age".result ISNULL
;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This indentation style isn't consistent with much of the other files.

@jimmytty

jimmytty commented Aug 5, 2025

Copy link
Copy Markdown
Contributor Author

@exercism/sqlite Thoughts on "easy" with a JSON object? Or, thoughts on using a JSON object vs a simple(r) output?

🤔 It's better just use a "common" result datatype to store both real and text (just the error description)? I can change this if you like and remove json at all.

@IsaacG

IsaacG commented Aug 6, 2025

Copy link
Copy Markdown
Member

🤔 It's better just use a "common" result datatype to store both real and text (just the error description)? I can change this if you like and remove json at all.

I don't think one is objectively better than the other. Hence me soliciting thoughts from the other maintainers. A JSON object is richer and more nuanced; it avoids a column that might hold a string or a number. It's "better" from the technical perspective of being more detailed. But it's more complicated. For an easy exercise, there's value in keeping things easy. Adding JSON over a plain value makes it "more" complicated. But with the example in the instructions.append, it might be only very slightly more complicated and still be easy. Or not.

@IsaacG

IsaacG commented Aug 6, 2025

Copy link
Copy Markdown
Member

A third option that was suggested by @BNAndras is to simply omit those error tests. Those don't add a ton of value and simplify things a fair bit. That would be in line with what we did in the grains and collatz exercises. I think that might be a very good option here.

@jimmytty

jimmytty commented Aug 6, 2025

Copy link
Copy Markdown
Contributor Author

A third option that was suggested by @BNAndras is to simply omit those error tests. Those don't add a ton of value and simplify things a fair bit. That would be in line with what we did in the grains and collatz exercises. I think that might be a very good option here.

So there's already a "pattern" I can follow. Great! I'll do that! 😁

@glennj

glennj commented Aug 6, 2025

Copy link
Copy Markdown
Contributor

I agree that the error test can be omitted.

An alternate implementation is to add an is_error INTEGER column to the space_age table, expecting a 0 or 1 value.

Comment thread exercises/practice/space-age/.meta/tests.toml Outdated
@IsaacG IsaacG changed the title * add practice exercise: space-age Add practice exercise: space-age Aug 6, 2025
@IsaacG IsaacG added x:action/create Work on something from scratch x:module/practice-exercise Work on Practice Exercises labels Aug 6, 2025
Co-authored-by: Isaac Good <IsaacG@users.noreply.github.com>
@IsaacG
IsaacG merged commit 031ecb1 into exercism:main Aug 6, 2025
2 checks passed
@jimmytty
jimmytty deleted the space-age branch August 8, 2025 22:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

x:action/create Work on something from scratch x:module/practice-exercise Work on Practice Exercises

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants