# Example Discussion - Predicate: group\_by/4

**URL:** <https://swi-prolog.discourse.group/t/example-discussion-predicate-group-by-4/3374>\
**Category:** Example - Discussion\
**Created:** [December 15, 2020, 12:12pm UTC](https://swi-prolog.discourse.group/t/example-discussion-predicate-group-by-4/3374 "2020-12-15T12:12:41Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![EricGT](https://avatars.discourse-cdn.com/v4/letter/e/f1d935/32.png) [@EricGT](https://swi-prolog.discourse.group/u/EricGT)\
**Post date:** [December 15, 2020, 12:12pm UTC](https://swi-prolog.discourse.group/t/example-discussion-predicate-group-by-4/3374/1 "2020-12-15T12:12:41Z")

</div>

This is just a sample topic to demonstrate an example discussion for the related group\_by/4 example.

The topic [Predicate: group\_by/4](https://swi-prolog.discourse.group/t/predicate-group-by-4/3373) holds the examples and this topic is to discuss the examples.

The code for the example was copied from [Group\_by/4 examples](https://swi-prolog.discourse.group/t/group-by-4-examples/2678) and I might just remove the topic from the Category [Useful Code](https://swi-prolog.discourse.group/c/useful-code/16) if leaving it in the [Example](https://swi-prolog.discourse.group/c/example/28) category works better.

I know some to many will disagree with the use of test cases in the example; I have to agree as I think a new user will just be confused by looking for a simple example and then be confounded by the burden of trying to understand test cases. So by putting this out there in the test cases, it brings the point to the level of a discussion.

Should examples be demonstrated as test cases?

Should examples first be given as simple examples and then be followed by a series of test cases?

---

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [December 15, 2020, 12:27pm UTC](https://swi-prolog.discourse.group/t/example-discussion-predicate-group-by-4/3374/2 "2020-12-15T12:27:58Z")

</div>

> [@EricGT](#):
>
> Should examples be demonstrated as test cases?

I quite strongly disagree with examples as tests. Simply use e.g. this below. Way easier to read for all uf us and for beginners even more so. We can create test cases out of this should we want to do so later.

```prolog
?- member(X, [a,b]).
X = a ;
X = b.

```

---

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [December 15, 2020, 12:37pm UTC](https://swi-prolog.discourse.group/t/example-discussion-predicate-group-by-4/3374/3 "2020-12-15T12:37:49Z")

</div>

Except for the use as test cases as discussed in [Example Discussion - Predicate: group\_by/4](https://swi-prolog.discourse.group/t/example-discussion-predicate-group-by-4/3374/2), I think examples should also minimize the amount of data. This set is rather big, which requires a lot of reading to figure out what it is doing. The relation to bagof/3 should IMO be at the end or (probably better) absent and in a separate example topic that compares similar aggregation options. Also comments about the examples should not be in code comment. Examples are a markdown document.

Notably the primary example (as files, in a file named after the example) should be short and only highlight a typical query on each sufficiently different mode.

---

<div class="post-metadata">

**Author:** ![EricGT](https://avatars.discourse-cdn.com/v4/letter/e/f1d935/32.png) [@EricGT](https://swi-prolog.discourse.group/u/EricGT)\
**Post date:** [December 15, 2020, 12:56pm UTC](https://swi-prolog.discourse.group/t/example-discussion-predicate-group-by-4/3374/4 "2020-12-15T12:56:00Z")

</div>

> [@jan](#):
>
> I think examples should also minimize the amount of data. This set is rather big, which requires a lot of reading to figure out what it is doing.

Changed in example.

> [@jan](#):
>
> The relation to [bagof/3](https://www.swi-prolog.org/pldoc/doc_for?object=bagof/3) should IMO be at the end or (probably better) absent and in a separate example topic that compares similar aggregation options.

Removed all the examples but one.

> [@jan](#):
>
> Also comments about the examples should not be in code comment.

Examples with comments were also removed.
