<FromGitter>
<Blacksmoke16> `We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil. Yet we should not pass up our opportunities in that critical 3%.`
<alex``>
zip looks nicer because we have the value directly, instead of arr[idx]
<FromGitter>
<Blacksmoke16> readability is an impt factor as well
<FromGitter>
<tenebrousedge> always use higher-order iterators if possible
<FromGitter>
<tenebrousedge> ```code paste, see link```
<FromGitter>
<Blacksmoke16> is what i do to generate the config file on install
<FromGitter>
<watzon> Hopefully shards will be able to do that in the future, but yeah, for now you need a script
<FromGitter>
<watzon> Make can handle it as well
<FromGitter>
<Blacksmoke16> ye
<FromGitter>
<tenebrousedge> make D:
<alex``>
Blacksmoke yep ^^
<FromGitter>
<Blacksmoke16> or really just add the binary to your github release and they can just download it and put it where they want w/o having to use crystal
<FromGitter>
<watzon> @tenebrousedge that's actually a rubocop thing
<FromGitter>
<watzon> Ameba as well
<FromGitter>
<tenebrousedge> @watzon my opinion may be shared by bbatsov, but I promise I came by it honestly. Did you mean to respond to alex though?
<FromGitter>
<watzon> Nope, just letting you know that your preference is actually a standard
<FromGitter>
<watzon> so 👍
<FromGitter>
<tenebrousedge> well, I do get the impression that you're probably a step ahead of me with regards to Crystal, but I'd like to think that I have the Ruby standard library and rubocop rules memorized. I'm not sure whether I would feel happier if that were or weren't true, though
<FromGitter>
<watzon> Well I should say that the standard is this: use if/else or unless whenever you want, however avoid unless/else.
alex`` has quit [Ping timeout: 272 seconds]
<FromGitter>
<bararchy> unless else is the devil
<FromGitter>
<tenebrousedge> I think I actually tried to use it in a Crystal program recently, but it didn't work, and that was probably a good thing
<mps>
straight-shoota: j8r: have you seen my msg last night => build of 0.29.0 failed in 'abuild check', with this http://tpaste.us/P0D1
bcardiff has joined #crystal-lang
bcardiff has quit [Client Quit]
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
<FromGitter>
<mwlang> I don't do unless / else, either. Would rather do if / else and just flip contents of the blocks around. ⏎ ⏎ ```code paste, see link``` ⏎ ⏎ when you use unless in a block, you're separating the logic from the action and that's what's making it challenging to follow the flow. [https://gitter.im/crystal-lang/crystal?at=5cfa6c27cea82952790b0e40]
<FromGitter>
<tenebrousedge> 👍
<FromGitter>
<tenebrousedge> I'm not sure I realized the subject was conditionals *within* a block. Those are usually best avoided altogether
<FromGitter>
<j8r> yes mps
<FromGitter>
<mwlang> @Blacksmoke16 > should just have to do ServerResponse wrapped in back ticks -- then it doesn't link automatically if I just do `ServerResponse`
<FromGitter>
<Blacksmoke16> are you referencing it within a different namespace?
<FromGitter>
<Blacksmoke16> if so yea, would have to provide the full "path"
<FromGitter>
<Blacksmoke16> when you run a file code is run top to bottom, so stuff you require first runs first, plus whatever code should execute that that require has
<FromGitter>
<Blacksmoke16> so like
<alex``>
why foo is successfully called but not defined yet?
<alex``>
in ruby t.rb:1:in `<main>': undefined local variable or method `foo' for main:Object (NameError)
<FromGitter>
<Blacksmoke16> maybe someone else can confirm this, but as far as i know compiler has a pass earlier on to identify/type everything so that when it runs it know about it
<FromGitter>
<Blacksmoke16> thats my understanding at least
<alex``>
make sense but surprise me
<FromGitter>
<Blacksmoke16> since its a compiler lang, vs ruby when is just executing it line by line
<alex``>
in a program, what is the benefits of using `Module Name; {code-here}; end` instead of directly `{code-here}`?
<FromGitter>
<Blacksmoke16> namespacing
<alex``>
which editor are you using Blacksmoke16 btw?
<FromGitter>
<Blacksmoke16> so you avoid name conflicts with other libs/crystal itself
<FromGitter>
<kinxer> BlackSmoke's example is better. :P
<FromGitter>
<Blacksmoke16> sublime
<FromGitter>
<Blacksmoke16> with crystal plugin
<alex``>
and remove the main function to put the body of main directly in the module?
<FromGitter>
<Blacksmoke16> yea
<FromGitter>
<Blacksmoke16> but might be better to take a more OOP approach than just one big block of code
<FromGitter>
<Blacksmoke16> like could you split any of this out into objects?
<FromGitter>
<Blacksmoke16> which would also make testing easier as you could test each piece of code on its own
<alex``>
I’ll try to improve my Crystal-fu
<alex``>
yeah I realized that
<alex``>
I’ll start by removing the main function
<FromGitter>
<Blacksmoke16> 👍
<FromGitter>
<PlayLights_twitter> hey is there any reason why HTTP::Server::Response is write only? I need to read it to write the response body on the log :(
<FromGitter>
<Blacksmoke16> cant you just call `gets_to_end` on it?
<FromGitter>
<Blacksmoke16> but it runs globally and isn't scoped to a specific `describe` block
<FromGitter>
<Blacksmoke16> but yea, a common way to doing it is to define something in your helper class that you can use in each spec
<FromGitter>
<Blacksmoke16> i can get you an example if you want
<FromGitter>
<Blacksmoke16> @PlayLights_twitter could maybe set the output IO of the response to a multiwriter and then writes to the response body would also be written to the other IO?
<mps>
j8r: patch arrived, thanks
<FromGitter>
<r00ster91> When iterating through something and I want to know whether this iteration is the last one, are there better ways to find that out than ⏎ ⏎ ```array.each_with_index(1) do |value, index| ⏎ index == array.size ⏎ end``` ⏎ ⏎ ? [https://gitter.im/crystal-lang/crystal?at=5cfa860465392c3b60d70326]
<FromGitter>
<j8r> mps 👌
<FromGitter>
<PlayLights_twitter> @Blacksmoke16 yeah I ended up doing that, im was messing with too many variants of IO
<FromGitter>
<Blacksmoke16> 👍
<alex``>
Blacksmoke16 yeah I would like a good practise to using data / test
<FromGitter>
<Blacksmoke16> then within my specs you can do `create_message(message: "Some message")`
<FromGitter>
<Blacksmoke16> to override specific values, or just do `create_message` to get the defaults
<alex``>
thx!
<FromGitter>
<Blacksmoke16> np
<FromGitter>
<Blacksmoke16> @r00ster91 not as far as i know
<FromGitter>
<tenebrousedge> @r00ster91 why not just deal with that element separately?
<FromGitter>
<r00ster91> @Blacksmoke16 I think I will go with the `array.each_with_index(1) do |value, index|` variant. I thought it's slower but it isn't actually ⏎ @tenebrousedge why dealing with it separately? I'm building a string with all the array elements so I'm iterating through the array and when I would want to do that seperately, outside of the loop then I would still have to check if it's the last element
<FromGitter>
<Blacksmoke16> im assuming so you dont want to add like a `,` to the last one?
<FromGitter>
<r00ster91> yep
<FromGitter>
<Blacksmoke16> i mean could just add a like `.chomp(',')`
<FromGitter>
<r00ster91> oh and because I want to use an "and" for the last element
<FromGitter>
<bew> similar, but without creating intermediate array `arr.each.first(arr.size - 1).join(", ") + " and #{arr.last}"`
<FromGitter>
<PlayLights_twitter> Hey, please some help, Why is this code invalid? `puts {success: true}.to_json` returns "Syntax error in eval:1: expecting token 'CONST', not 'true'"
<FromGitter>
<bew> try adding parenthesis for puts
<FromGitter>
<tenebrousedge> @bew are you entirely sure that `first` doesn't create an intermediate array?
<FromGitter>
<bew> yes
<FromGitter>
<bew> with `arr.each` I make an iterator, then doing `first` on it will just give me the first N elements when I want to iterate on it (in `join`)
<FromGitter>
<PlayLights_twitter> Interesing `Error in line 1: undefined method 'to_json' for NamedTuple(success: Bool)`
<FromGitter>
<Blacksmoke16> whichever one you find more readable
alex``` has joined #crystal-lang
alex`` has quit [Ping timeout: 248 seconds]
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
<mps>
j8r: I'm building 0.29.0 on both arches and preparing to push it to repo. Do you mind to put you in commit message in relation to patch you posted
<mps>
thought to put full name but wasn't sure will you agree
<FromGitter>
<tenebrousedge> Crystal != Ruby, but Crystal is derivative of Ruby, and many things that make sense for Ruby also make sense for Crystal. And vice versa, but the Rubyists seem to have a knee-jerk attitude against adopting any Crystalisms
<FromGitter>
<j8r> Really? That was a one line patch, I don't mind
<FromGitter>
<j8r> :)
<FromGitter>
<tenebrousedge> Crystal is more open to good ideas, no matter their source
<FromGitter>
<watzon> True, just saying the core devs don't really accept "A is in Ruby so Crystal should also have A" as an argument
<mps>
anyway, you helped a lot to have crystal in alpine and you deserve credits
<FromGitter>
<j8r> I guess, thanks mps 😅
<mps>
and straight-shoota (between others) of course, to not forget
<FromGitter>
<j8r> How did you do it so fast?
<mps>
hmm, I thought I'm slow :)
<mps>
I started last night with building with different options and test to see what will be 'best' for now