Skip to content
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

final submission #27

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

RadhikaDh
Copy link

Radhika Dharulkar
46911479

def counter(value \\ 0) do
#state = %{:count => value }
Copy link
Contributor

Choose a reason for hiding this comment

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

-2 layout

Please try to indent things correctly

@@ -1,6 +1,24 @@

defmodule Ex02 do

def new_counter(value) do
Copy link
Contributor

Choose a reason for hiding this comment

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

-10

This code contains a bug and a messy thing :)

The bug is that you use Agent.get followed by update. This introduces a race condition. It two processes access the counter at the same time, they could both receive the same value. Making the get_and_update atomic means that won't happen.

-4 idiom

new_counter returns {:ok, pid}, which means that next_value has to deconstruct this to get the pid.

The :ok part is really only used to make sure the agent was created. It should never leave new_counter:

def new_counter(value) do
   { :ok, count } = Agent.start(fn -> value end)
  count
end

@@ -60,7 +60,15 @@ defmodule Ex03 do
"""

def pmap(collection, process_count, function) do
« your code here »
no_of_items = Enum.count(collection)/process_count
Copy link
Contributor

Choose a reason for hiding this comment

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

-2 layout

indentation, plus inconsistent use of spaces in parameter lists and around '='s.

-4 idiom

This is just crying out to be a pipeline.

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.

2 participants