« first day (893 days earlier)      last day (2375 days later) » 

user4651282
11:43 AM
@UfukHacıoğulları, hello and welcome
 
12:09 PM
@Atomic_alarm Hello
Thanks
 
 
2 hours later…
1:46 PM
Oh, hi @UfukHacıoğulları
If you've got questions just drop them here. One of us will be along eventually.
We're all in different timezones, though, so it can be somewhat high latency conversation.
 
2:21 PM
@zxq9 Thank you. That's great.
I was actually wondering if this type of code is common in Erlang.
Pq1 = priority_queue:new(compare),
Pq2 = priority_queue:enqueue(8, Pq1),
Pq3 = priority_queue:enqueue(3, Pq2),
Pq4 = priority_queue:enqueue(5, Pq3),
Pq5 = priority_queue:enqueue(4, Pq4),
Pq5 = priority_queue:enqueue(9, Pq4),
Pq6 = priority_queue:enqueue(0, Pq5),
Suffixing a variable with a number and then incrementing it whenever it changes.
 
user4651282
@UfukHacıoğulları I guess so, but better avoid useless variables.
 
user4651282
If you need repetitive actions you use functions (own or from libraries).
 
3:09 PM
Like an enqueue method that takes an array parameter, right?
Makes sense
 
user4651282
yes, many modules has function from_list to convert data(or rather their representation) from list to other data structure.
 
I'm also writing my first unit tests now. Is it a good practice to use pattern matching for assertions? assertEqual in EUnit seems redundant if I can do it with pattern matching.
 
 
1 hour later…
4:21 PM
If you are active on Code Review, please take a look at my question.
https://codereview.stackexchange.com/questions/176575/priority-queue-in-erlang
Thanks for all the help.
Have a nice evening.
 
user4651282
5:15 PM
@UfukHacıoğulları assertEqual is provided more full information about errors so usually prefer use it. I think zxq9 will give a more complete review than I can. But if he doesn't have time... tomorrow I'll write my own.
 
user4651282
Thanks, have a nice evening
 
9:54 PM
@UfukHacıoğulları Yeah, what @Atomic_alarm was saying is spot on. This business of writing out a bunch of useless variables is not a good way to do things. If you need to add things to a queue in a certain way, then use a fold, list comprehension, or explicit recursion to loop.
When it comes to other variables you are going to update before returning (like a structure you are modifying) naming it with a number is definitely less clear than naming it with something that has a meaning. For example, if I'm returning a State variable I might have:
foo(Bar, State = #s{counter = Counter}) ->
    {ok, Count} = do_stuff(Bar),
    NewState = State#s{counter = Counter + Count}
    ok = log(info, "Did the thingy with ~tp", [Bar]),
    NewState.
If I have a queue that I need to plug values into, then I would take a list and fold over it:
do_stuff(ListOfThings) ->
    Enqueue = fun(T, Q) -> priority_queue:enqueue(T, Q) end,
    lists:foldl(Enqueue, priority_queue:new(compare), ListOfThings).
That would iterate over my ListOfThings and return a populated queue.
The example above with foo/2 is extremely contrived, of course -- you would probably just have State#s{counter = Counter + Count}. as the last line, but sometimes you modify a variable once and then need to reference it later before returning and using a name like NewState or NewThingy is much more informative than State2 or whatever.
If you find yourself doing
Thing1 = ...,
Thing2 = ...,
Thing3 = ...,
% ...
It is very likely you are writing unusually long functions (like longer than 20 lines in the body) and it is a definite sign you should think about breaking the function up, because its doing way too much stuff.
This is basically a code smell.
 

« first day (893 days earlier)      last day (2375 days later) »