Skip to content

Adding Example Code to Sorting Algorithms #240

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 21, 2018
Merged

Adding Example Code to Sorting Algorithms #240

merged 2 commits into from
Jul 21, 2018

Conversation

Wesley-Arrington
Copy link
Contributor

@Wesley-Arrington Wesley-Arrington commented Jul 10, 2018

My current understanding is that code in the AAA is supposed to show a main() function which runs the algorithm. So I updated the java sorting algorithms to reflect this.

  • Changed bubble_sort.md so main() is now shown
  • Changed bogo_sort.md so main() is now shown

@june128 june128 added the Implementation Edit This provides an edit to an algorithm implementation. (Code and maybe md files are edited.) label Jul 10, 2018
@Butt4cak3
Copy link
Contributor

To be honest, I don't think we're even sure when to show the main function and when not to. Some chapters intentionally only show the algorithm in question, others show full code examples with a main function.

We should probably agree on something or come up with a rule. Let me summon @leios, @julianschacher, @Gathros, @jiegillet and @Gustorn real quick. They probably have opinions on this.

@june128
Copy link
Member

june128 commented Jul 11, 2018

It's true that we don't have a Code Example section in some algorithm chapters. Only parts of the actual code are shown there.
For chapters with the Code Example section, the whole code should be shown imo and I also handle it like this with my C# imports.

With the Bubble Sort and Bogo Sort chapters we don't have a Code Example section, but we should add one maybe. It would make the chapter more comprehensive.

@Butt4cak3
Copy link
Contributor

We have a few chapters in which only the algorithms themselves are imported. Maybe we should always add one code block at the very bottom that contains a working, compilable/runnable example.

@june128
Copy link
Member

june128 commented Jul 11, 2018

@Butt4cak3 yeah, that was what I was thinking of and I support that

@Wesley-Arrington
Copy link
Contributor Author

I totally agree with both of you that there should be one section just showing the algorithm and then one example code section which has a working example.

I just added in an example code section for Bubble sort and Bogo sort

@june128
Copy link
Member

june128 commented Jul 12, 2018

@CDsigma Hey, I found a little problem with the C# imports of the Example Code sections and there were also a few other adjustments to be made. Therefore I made a PR, to your javaSorting-Branch, which should be safe to merge: https://github.com/CDsigma/algorithm-archive/pull/1

@june128
Copy link
Member

june128 commented Jul 12, 2018

The restructuring of the chapters seems good now; so from my side everything is ok :)
I just want to let @Butt4cak3 look over it as well and then he can decide to merge the PR or request more changes/let someone else look at it/whatever.

@Butt4cak3
Copy link
Contributor

By the way, why do we even still have the language specific headlines for the full example codes (### Java, ### Haskell, ...)? Also related to #245.

@leios
Copy link
Member

leios commented Jul 12, 2018

Ah, I guess you are right. I had them in initially because we didn't have the theme api. There's no harm in removing them now since we can indicate what language you are reading with the theme-api.

@Butt4cak3 Butt4cak3 mentioned this pull request Jul 12, 2018
@Wesley-Arrington
Copy link
Contributor Author

Just removed the language headlines and changed 'Example Code' to using ##

@Butt4cak3
Copy link
Contributor

Butt4cak3 commented Jul 12, 2018

You also kinda just copied the full code imports so that we now have the same, full code twice for some languages like C++.

I think now that we're already working on it, we should do it right. I think the first code block should show only the bubbleSort function, no shuffle no isSorted and no main - in every language. Then there should be the "Example Code" section with all the full examples.

@june128
Copy link
Member

june128 commented Jul 12, 2018

I agree with @Butt4cak3 there, that makes the most sense for these chapters. For functions like isSorted() it's pretty clear what they do even without seeing the implementation. And if people want to see, how it actually works, they can look at the bottom.

@Wesley-Arrington
Copy link
Contributor Author

Wesley-Arrington commented Jul 15, 2018

I agree it makes sense to only show the bubble sort and bogo sort functions for the first part and then in the 'Example Code' section to show all the code. I adjusted the .mds accordingly.

@Wesley-Arrington Wesley-Arrington changed the title Showing main() for Java sorting algorithms Adding Example Code to Sorting Algorithms Jul 15, 2018
@leios
Copy link
Member

leios commented Jul 15, 2018

Sorry it has taken me so long to get to this PR. I agree. The intent was to have the full code in the Example Code section and have snippets in the bulk text. For bubble and bog sort, this idea was not fully realized because it was early in the process and we hadn't committed to the "multi-lang" feature.


{% method %}
{% sample lang="jl" %}
[import:1-14, lang:"julia"](code/julia/bogo.jl)
Copy link
Member

Choose a reason for hiding this comment

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

Why do some of the languages have line numbers to import and others don't? Shouldn't the example code section just import an entirely working code sample?

Copy link
Member

Choose a reason for hiding this comment

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

It should. I guess that needs a change.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yup. That's pretty much what I tried to say in my most recent comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry about that, I accidentally messed up on the Julia code for both Bubble Sort and Bogo Sort in the Example Code section. I just made a commit to fix this.

The rest of the line numbers given are to hide unnecessary comments at the beginning of the programs saying who created them. It seems unnecessary to show these comments since it doesn't provide useful information to the reader. Additionally, there is already the contributors.md file so the programmers are receiving credit elsewhere. I think there are three options for what can be done here:

  1. Keep it as is (meaning hide those lines by modifying the .md file)
  2. Modify the code to remove the unnecessary comments
  3. Show the comments and then sort out what should be done if anything in a different PR

Or, another option I may have missed.
Give me your thoughts on what you think should be done 👍

@june128
Copy link
Member

june128 commented Jul 19, 2018

You excluded the comments in some instances, when you imported the whole code at the bottom. These comments often show the contributor and I think they shouldn't be excluded.

@Wesley-Arrington
Copy link
Contributor Author

Wesley-Arrington commented Jul 19, 2018

I disagree that we should be showing those comments but I also don't think that this is a key issue for the project.

I just made a commit to show all comments in the 'Example Code' section. This should help to simplify this pull request.

In the future I may make an issue to help further the discussion around these comments, which show the contributor at the top of the program, since I think they add unnecessary clutter.

@june128
Copy link
Member

june128 commented Jul 19, 2018

Thank you :) It's the way it's handled until now and for the sake of holding to standards it's good to include it here as well.

Aside from that: I think showing the contributors and giving them credit is a nice gesture, we should keep up.

@june128
Copy link
Member

june128 commented Jul 19, 2018

But opening an issue might not be a bad thing. The credit works good for code files, that got contributed in only one PR, but as soon as they get revised, reworked and improved, that whole thing is getting complicated.

- Added example code sections showing all code
- Changed code segments shown to only show bubble sort functions
Copy link
Contributor

@Butt4cak3 Butt4cak3 left a comment

Choose a reason for hiding this comment

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

This PR has been open for a while and I think it's time to finally merge it, so let's try to finish it up.

The partial code import for C BubbleSort is off by one line. Can you change the range from 11-21 to 10-20?

That's all. Fix that up real quick and I'll merge this.

@Wesley-Arrington
Copy link
Contributor Author

Just fixed the code import for C

@Butt4cak3
Copy link
Contributor

Good work!

@Butt4cak3 Butt4cak3 merged commit 0f667ed into algorithm-archivists:master Jul 21, 2018
@Wesley-Arrington Wesley-Arrington deleted the javaSorting branch July 21, 2018 19:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Implementation Edit This provides an edit to an algorithm implementation. (Code and maybe md files are edited.)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants