Skip to content

Conversation

@meatball133
Copy link
Member

@meatball133 meatball133 commented Dec 31, 2025

This is apart of making ostruct an optional concept: https://forum.exercism.org/t/openstruct-is-now-officially-discouraged/17490

@meatball133 meatball133 force-pushed the add-hashes branch 2 times, most recently from 88c383c to c4876ae Compare December 31, 2025 17:00
@meatball133
Copy link
Member Author

I would say we are a bit in a limbo, though, the array and enumeration concepts are connected to one exercise, and personally, I think it makes sense to introduce arrays before hashes. But the enumeration concept mentions hashes. So either I think enumeration should be stripped out of hashes, which might not make sense. Instead it might make sense to make a separate exercise for arrays so we can have. arrays => hashes => enumeration. I think this shouldn't necessarily hold this pr, since it won't make things worse in my opinion, since not having a hash concept to begin with isnt ideal either.

@meatball133
Copy link
Member Author

An option could be to temporairly place hashes over arrays

@kotp
Copy link
Member

kotp commented Jan 7, 2026

An option could be to temporairly (sic) place hashes over arrays

I do tend to teach "collections" rather than independent data structures, since other than the data structure itself, the idea of Enumerable being the thing that gives a lot of power. What do you think about taking that approach for a concept, rather than the concept of "map/dictionary" specifically? I have not looked at the changes in this PR yet, though. Just got back to my computer after a two week break (travelling).


Even though hashes are unordered collections, Ruby maintains the insertion order of key-value pairs.
This means that when you iterate over a hash, the pairs will be returned in the order they were added.
However, deleting elements may affect the order of remaining elements.
Copy link
Member

Choose a reason for hiding this comment

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

Expand on this, is the order at that point of operation undeterminate? Citation would be helpful for further exploration, and historically in Ruby, this is an interesting point as well.

my_hash = { 1 => "one", :two => 2, "three" => [3, "three"] }
```

Alternatively if the keys are symbols, you can use a more JSON-style syntax:
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps avoid JSON reference. But maybe mention the "newer syntax as of Ruby 1.9" form as shown.

my_hash = { name: "Alice", age: 30, city: "New York" }
```

You can create an empty hash using the `Hash.new` method:
Copy link
Member

Choose a reason for hiding this comment

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

Capitalize "Hash" when speaking of the type specifically or the object itself, since hash is also a method and an idea. (Even if it weren't this situation, I would likely suggest capitalization as well as code syntax for the specific thing.)


## Accessing values

You can access values in a hash using their corresponding keys, the syntax reminds of array indexing, but using the key instead of an index:
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
You can access values in a hash using their corresponding keys, the syntax reminds of array indexing, but using the key instead of an index:
You can access values in a `Hash` instance using its corresponding keys, the syntax reminds of array indexing, but using the key instead of an index:

You can access values in a hash using their corresponding keys, the syntax reminds of array indexing, but using the key instead of an index:

```ruby
my_hash = { "name" => "Alice", "age" => 30, "city" => "New York" }
Copy link
Member

Choose a reason for hiding this comment

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

No space inside Hash delimiters, similar to Array and Range, save the space inside {} delimiters for blocks.

Suggested change
my_hash = { "name" => "Alice", "age" => 30, "city" => "New York" }
my_hash = {"name" => "Alice", "age" => 30, "city" => "New York"}

Alternatively, present it as:

Suggested change
my_hash = { "name" => "Alice", "age" => 30, "city" => "New York" }
my_hash = {
"name" => "Alice",
"age" => 30,
"city" => "New York"
}

Indentation adjusted for readability (this is how I style my key/value pairs reducing eye jitter), and not necessary, but might be nice to have.

@@ -0,0 +1,38 @@
class GrossStore
UNITS = {'quarter_of_a_dozen' => 3, 'half_of_a_dozen' => 6, 'dozen' => 12, 'small_gross' => 120, 'gross' => 144, 'great_gross' => 1728}.freeze
Copy link
Member

Choose a reason for hiding this comment

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

Nice that there is no space inside the delimiter, but why the freeze? We advertise this as a mutable object, but then make it immutable here?

Also blank line after class definition line is a signal of "topic change" and creates a paragraph of sorts.

This is an exemplar, not just an example, so we should apply opinions here to be that exemplar.

But I will not critique explicitly here. Welcome to discuss it on Discord, though, if you want to (even pair program through it if you want).

Or even as a product of a mentor request! ;)

@@ -0,0 +1,24 @@
class GrossStore
UNITS = { 'quarter_of_a_dozen' => 3, 'half_of_a_dozen' => 6, 'dozen' => 12, 'small_gross' => 120, 'gross' => 144,
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
UNITS = { 'quarter_of_a_dozen' => 3, 'half_of_a_dozen' => 6, 'dozen' => 12, 'small_gross' => 120, 'gross' => 144,
UNITS = {'quarter_of_a_dozen' => 3, 'half_of_a_dozen' => 6, 'dozen' => 12, 'small_gross' => 120, 'gross' => 144,

As a minimum, no space inside delimiters.

Perhaps a columnar presentation of the Hash as well, easier to see patterns, etc., than having a horizontal showing of this.

UNITS = { 'quarter_of_a_dozen' => 3, 'half_of_a_dozen' => 6, 'dozen' => 12, 'small_gross' => 120, 'gross' => 144,
'great_gross' => 1728 }.freeze

attr_reader :bill
Copy link
Member

Choose a reason for hiding this comment

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

public method definition above the private method initialize is something that I personally detest, it suggests something that is untrue (that initialize is perhaps not private, since in this organization it is in the midst of public method definitions.

],
"prerequisites": [
"advanced-enumeration"
"hashes"
Copy link
Member

Choose a reason for hiding this comment

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

This should be capitalized, as hashes are created by using hash method calls, and is something different.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is the slug

],
"prerequisites": [
"ostruct"
"hashes"
Copy link
Member

Choose a reason for hiding this comment

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

... same here.

@meatball133
Copy link
Member Author

I do tend to teach "collections" rather than independent data structures, since other than the data structure itself, the idea of Enumerable being the thing that gives a lot of power. What do you think about taking that approach for a concept, rather than the concept of "map/dictionary" specifically? I have not looked at the changes in this PR yet, though. Just got back to my computer after a two week break (travelling).

I think in a way that is a good idea, I think however that the concept might end up being too big. Since this concept is around 200 lines say array is the same and then what about other collections (such as sets). It might make sense to have these after each other but don't know about having a single big one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants