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

assinment 3 #34

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

shashitekula
Copy link

Hi Professor,

Please find the attached assignment

thank you
Shashi Tekula

def counter(value \\ 0) do

receive do
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 indent the block of code under the {:next, from} line.

end


def new_counter(value) do
pid = spawn(Ex01, :counter, [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

This generates a warning

-1 layout

end


def next_value(from) do
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

Layout is really an important part of programming, because it aids understanding.

# end


test "counter using an agent" do
Copy link
Contributor

Choose a reason for hiding this comment

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

-5

This code contains a race condition, because it does a get followed by an update. Imagine two processes getting the next value at the same time. Both do a get, and both receive the same value.

{:ok,count} = Agent.start_link(fn -> value end)
end

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.

-2 idiomatic

I'm not sure why you add an extra start_link function.

Also, your new_counter function returns {:ok, pid}, but the :ok is
not useful anywhere. It should rally just return the pid:

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

def pmap(collection, process_count, function) do
« your code here »
end
count_value = 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.

-4 idiomatic

You should use pipelines, rather than temporary variables here.

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