<FromGitter>
<j8r> What do you think about this technology? Can it have a place in Crystal?
snsei has joined #crystal-lang
<FromGitter>
<j8r> The main issue of ARC vs GC is the handling of retain cycles
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 264 seconds]
return0e has joined #crystal-lang
Guest93774 is now known as lemur
lemur has quit [Changing host]
lemur has joined #crystal-lang
lemur is now known as baweaver
snsei has quit [Remote host closed the connection]
<FromGitter>
<faustinoaq> @j8r Oh, nice, I found this: ⏎ ⏎ > modern GC's are usually much more advanced using an object generation system, tri-color sets etc, and also perform other tasks such as defragmentation of the program's memory space by moving the objects to a contiguous storage space, this is the reason why GC'ed languages such as C# and Java do not allow pointers. One significant weakness of tracing garbage collectors
<FromGitter>
... is that class destructors are no longer deterministic, that is the programmer cannot tell when an object is going to be garbage collected in-fact GC'ed languages do not even allow the programmer to specify a class destructor, thus classes can no longer be used to encapsulate the management of resources such as file handles, da ... [https://gitter.im/crystal-lang/crystal?at=5aab0f0b27c509a77469e7aa]
<FromGitter>
<j8r> I've used `delete` ans then `squeeze` :)
<FromGitter>
<straight-shoota> It's similar to cadmium, but not a native Crystal implementation
<FromGitter>
<straight-shoota> @KINGSABRI `payload` is a JSON::Any which can't be used as an argument to `Base64.encode`
<FromGitter>
<straight-shoota> you should probably use `payload.as_s`
<FromGitter>
<KINGSABRI> Ahaaa
<FromGitter>
<KINGSABRI> is there any thing list Pry in crystal ?
<FromGitter>
<KINGSABRI> this will make things easier
<FromGitter>
<straight-shoota> not really
<FromGitter>
<straight-shoota> crystal is compiled so you can't modify the code at runtime
<FromGitter>
<KINGSABRI> I understand, and thanks for clarify this ⏎ but it can be something list instant compilation or so, correct me
<FromGitter>
<straight-shoota> there is ICR but it essentially recompiles and reruns the code every time you run a command. so it's not instantly and can have unexpected results
<FromGitter>
<straight-shoota> theoretically, yes. but a compiled crystal program doesn't have any reference of classes, methods, variable names etc. the high-level structure is all gone
<FromGitter>
<KINGSABRI> I see, I have to figure an easy way to do so. ⏎ and yeah I have to adapt with compiled langauge more, I use Ruby all the time so I should not trade Crystal as Ruby
<FromGitter>
<straight-shoota> usually you can get quite far with `pp`
<FromGitter>
<alex-lairan> `gdb` working with crystal? if yes, it could be a cool trade off
<FromGitter>
<straight-shoota> yes
<FromGitter>
<straight-shoota> I never really had to use it though
<FromGitter>
<alex-lairan> ok, @KINGSABRI you can learn `gdb`, it's had in a first time, but it's a good tool
<FromGitter>
<KINGSABRI> I know gdb but I never had to use it for coding, only for security research
<FromGitter>
<KINGSABRI> good point though
<FromGitter>
<KINGSABRI> does visual studio code has compile option for crystal ?
<FromGitter>
<KINGSABRI> I installed the crystal plugin but I can see any different it works as text editor more than IDE in crystal
<FromGitter>
<Blacksmoke16> @bew Thanks i must have missed that
yargl has joined #crystal-lang
yargl has quit [Client Quit]
<FromGitter>
<Blacksmoke16> im doing a crystal implementation of the Simplex LP algorithm, and i use infinity to show that the the RHS value is either negative or 0, i.e. unsolvable, so that i can have an easy `raise "Problem has no solution with given criteria" if ratios.all?(&.infinite?)`
<FromGitter>
<Blacksmoke16> is there a reason why `.infinite?` is only on Float, and not Number so it can be used with Ints?
Disrecollection has joined #crystal-lang
<FromGitter>
<KINGSABRI> @bew yes
DTZUZO has joined #crystal-lang
<RX14>
@Blacksmoke16 integers don't have a concept of infinity...
<RX14>
but you can do json.as_h["payload"] = "1111"
<FromGitter>
<KINGSABRI> aha , I see
<RX14>
typically you'd want to avoid JSON::Any where possible though
<FromGitter>
<KINGSABRI> I was confused because in Ruby, JSON.parse returns a hash be default
<RX14>
JSON::Any is just a hack to enable JSON.parse in crystal to be usable
<RX14>
but for faster and more robust parsing you usually use JSON.mapping and from_json on various objects
<FromGitter>
<KINGSABRI> > **<RX14>** typically you'd want to avoid JSON::Any where possible though ⏎ I do `JSON.parse(ARGV[0])` and it returns `JSON::Any` already
<FromGitter>
<KINGSABRI> > **<RX14>** most people don't use JSON.parse ⏎ Sorry no arguing here, but I do see most of people are using JSON.parse, in Ruby
<RX14>
in ruby sure
<RX14>
but not crystal
<RX14>
they're very different languages
<FromGitter>
<alex-lairan> 👍
<FromGitter>
<alex-lairan> You can build schema, it's more efficient, and sure :)
<RX14>
typically you already know the structure of your JSON before you parse
<FromGitter>
<KINGSABRI> I agree, maybe I still didn't see a lot of Crystal code out there to change my behavior
<FromGitter>
<KINGSABRI> > **<RX14>** typically you already know the structure of your JSON before you parse ⏎ ⏎ Typically, yes, but is't not the case all the time since most of my code for security proposes
<RX14>
no it's not the case all the time
<RX14>
that's why I said typically :)
<RX14>
if JSON::Any was useless we'd remove it from the language
<RX14>
but if you can use JSON.mapping instead it's usually better
<RX14>
it's far more type safe and easy to use
<RX14>
since you just define your objects and get a bunch of objects out instead of JSON::Any
Disrecollection has joined #crystal-lang
duane has quit [Ping timeout: 264 seconds]
<FromGitter>
<j8r> Would be nice an auto mapping :)
<FromGitter>
<j8r> Oh yes he has spoken to me about this, but not exactly what we need: it's written in Javascript, we will need to rewrite it in Crystal
<RX14>
why
<FromGitter>
<j8r> to modify unknown in advance/changing jsons
<RX14>
But how
<RX14>
You can't eval the generated crystal code
<FromGitter>
<j8r> yes :/
<RX14>
Besides it doesn't matter because you can generate the mapping but that's useless without any code to use the mapping
<RX14>
And that code still needs to be written by a human
<RX14>
And is dependant on the mapping
<RX14>
So it's pointless
<RX14>
A web tool is fine
alex`` has joined #crystal-lang
<FromGitter>
<j8r> you're right. I was finding a way to avoid writing huge mappings that constantly change
<RX14>
but why do they constantly change??
<FromGitter>
<j8r> I was exaggerating a bit , but I take a bunch of upstream projects, that have their JSON configurations/API. They often do micro changes here and here
rohitpaulk has quit [Ping timeout: 240 seconds]
Disrecollection has quit [Ping timeout: 252 seconds]
<FromGitter>
<alex-lairan> @KINGSABRI it's a tool like any other tool. ⏎ ⏎ If you have to get a huge JSON (from facebook or AWS for example), it's cool to have a tool who generate this for you.
<FromGitter>
<faustinoaq> > I installed the crystal plugin but I can see any different it works as text editor more than IDE in crystal ⏎ ⏎ @KINGSABRI The vscode-crystal-lang extension is just for highlighting, formatting, diagnostics and some other code writing capabilities. ⏎ ⏎ Debugging crystal generated binaries isn't supported yet, so you should use other debugging extensions like native-debug
<FromGitter>
<KINGSABRI> I'll try it, I would love to see this while learning Crystal
<FromGitter>
<KINGSABRI> Just need more time before I introduce it to the info sec community
<FromGitter>
<faustinoaq> Currently vscode-crystal-lang is implemented on Node.js ⏎ I think in the future I can replace it by scry ⏎ Actually scry is pretty small (aprox. 1MB with stripped symbols), so I can try to embed it on the extension, providing new awesome features without user intervention required 🎉
<FromGitter>
<KINGSABRI> i love that
<FromGitter>
<faustinoaq> > Just need more time before I introduce it to the info sec community ⏎ ⏎ Oh, nice, if they want to see a fast introduction try https://learnxinyminutes.com/docs/crystal/ ⏎ ⏎ BTW, There is NeuralLegion (https://www.neuralegion.com/) (ping @bararchy) a company about security that uses nextploit, their core tool/product made in crystal ... [https://gitter.im/c
<FromGitter>
<KINGSABRI> general question here, is Windows support is close? no close plan,yet?
<FromGitter>
<faustinoaq> Windows support is on going, mainly by community (RX14 @straight-shoota, @txe and other enthusiast ) ⏎ ⏎ Windows port is hard and requires a lot of time and work, see progress here: https://github.com/crystal-lang/crystal/issues/5430
<FromGitter>
<KINGSABRI> of course, all respect to their efforts
<FromGitter>
<bararchy> @KINGSABRI hi dude, awesome to see more infosec people coming to Crystal, seeing your answer regarding gdb I guess you're an exploit developer?
<FromGitter>
<bararchy> Oh, you're the author of rubyfu, mad respect then :)
Disrecollection has joined #crystal-lang
<FromGitter>
<KINGSABRI> @bararchy hello there! yes, and I want to make something like Rubyfu book for Crystal ⏎ But I need to know the language first
<FromGitter>
<KINGSABRI> @bararchy thanks man, glad you like it. ❤️
<FromGitter>
<bararchy> That would be great indeed
<FromGitter>
<KINGSABRI> yeah, I think Go is going viral in infosec community due it's speed. But when I found Crystal I think there is no way to go with Golang
<FromGitter>
<Sevensidedmarble> I think windows supports going to be a huge boon to crystals adoption
<FromGitter>
<KINGSABRI> Crystal is so fast as much as I understand I saw from benchmarks
<FromGitter>
<KINGSABRI> @Sevensidedmarble yeah indeed , as this community still young, I really encourage the community to do spread the language and not stay humble
<FromGitter>
<KINGSABRI> I hope crystal community support each other like Python, see python community they just love to contribute to each other projects ⏎ ⏎ It's cultural thing
<FromGitter>
<KINGSABRI> @bararchy that's why I asked if someone is working in infosec here to work together
<FromGitter>
<Sevensidedmarble> also probably the improving the garbage collector I'd imagine must be a pretty high priority for the maintainers...
<FromGitter>
<KINGSABRI> yeah, that's right
<FromGitter>
<Blacksmoke16> Did a benchmark of solving an LP problem 10,000 times in Ruby vs Crystal
<FromGitter>
<Sevensidedmarble> I think the possibility of more interop between crystal and ruby, like writing ruby extensions in crystal also has the possibility to boost the language tremendously
<FromGitter>
<Blacksmoke16> biggest roadblock coming from Ruby was having to deal with the Typings, but that is to be expected
<FromGitter>
<Sevensidedmarble> Is crystal your first statically typed language?
<FromGitter>
<Blacksmoke16> officially yea
<FromGitter>
<KINGSABRI> for me, you can say yes
<FromGitter>
<faustinoaq> > also probably improving the garbage collector I'd imagine must be a pretty high priority for the maintainers... ⏎ ⏎ @Sevensidedmarble Check this: https://github.com/ysbaddaden/gc
<FromGitter>
<KINGSABRI> C++ and Java were long long time a go
<FromGitter>
<Blacksmoke16> only other is TypeScript but thats not really officially statically typed
<FromGitter>
<Blacksmoke16> best you can do in js i guess
<FromGitter>
<Sevensidedmarble> that's very interesting @faustinoaq
<FromGitter>
<Sevensidedmarble> wow that looks impressive
<FromGitter>
<Sevensidedmarble> that would be awesome
<FromGitter>
<Sevensidedmarble> that's the only performance concern
<FromGitter>
<KINGSABRI> guys, why single quotes is not like double quotes in Crystal? eg `require 'json'` = error but `require "json"` is fine ?
<FromGitter>
<Sevensidedmarble> strings are always " "
<FromGitter>
<Sevensidedmarble> ' ' is reserved for chars
<FromGitter>
<faustinoaq> > I think the possibility of more interop between crystal and ruby, like writing ruby extensions in crystal also has the possibility to boost the language tremendously ⏎ ⏎ I think the possibility of more interop between crystal and ruby, like writing ruby extensions in crystal also has the possibility to boost the language tremendously
<FromGitter>
<bararchy> @KINGSABRI cool to hear, as currently there isn't much infosec community around Crystal one of my few OS project is this https://github.com/bararchy/sslscanner the more relevant one are sadly commercial and close. Though we do try to export stuff out as OS
<FromGitter>
<faustinoaq> > so I'd never want to subject myself to extending ruby with c ⏎ ⏎ There is also the option to write Ruby extensions using Rust https://usehelix.com/ 😜
badeball has joined #crystal-lang
<FromGitter>
<KINGSABRI> > @KINGSABRI cool to hear, as currently there isn't much infosec community around Crystal one of my few OS project is this https://github.com/bararchy/sslscanner the more relevant one are sadly commercial and close. Though we do try to export stuff out as OS ⏎ ⏎ I like the idea
<FromGitter>
<faustinoaq> > more relevant one are sadly commercial and close ⏎ ⏎ @bararchy I think that's not an issue, open source is good, but private projects will make crystal more enterprise alike 😄
<FromGitter>
<faustinoaq> I hope to make some products using crystal in the future, with free options and paid licenses with support 😉
gewo has joined #crystal-lang
<FromGitter>
<KINGSABRI> > > more relevant one are sadly commercial and close ⏎ @bararchy I think that's not an issue, open source is good, but private projects will make crystal more enterprise alike 😄 ⏎ ⏎ I agree ⏎ ... [https://gitter.im/crystal-lang/crystal?at=5aabed07458cbde55740eee5]
<FromGitter>
<KINGSABRI> Build system level services, Learning machine, desktop applications , and of course web framework but don't let people know you as a framework's language like Ruby
<FromGitter>
<KINGSABRI> Golang was smart at this point
<FromGitter>
<KINGSABRI> the way they introduced them self to the market
<FromGitter>
<bararchy> @KINGSABRI I would love seeing Metasploit using Crystal :) its so much easier working with low level data, writing exploits is really fun with Crystal using Bytes and not storing everything inside a string
<FromGitter>
<Sevensidedmarble> well being google definitely helps
<FromGitter>
<Sevensidedmarble> they could probably make Google Brainfuck and people would love it
<FromGitter>
<KINGSABRI> @Sevensidedmarble , no doubt. But google was even smart in introducing the language. ⏎ I really belive that Crystal is much nicer and make sense that Golang (ugly code)
<FromGitter>
<KINGSABRI> @bararchy Ruby is awesome in the way of usage to me. However, speed is sometimes un-negotiable thing when you talk with business
<FromGitter>
<KINGSABRI> I wish Crystal provide some cool low level play ground to use it in heavy duties task in security
<FromGitter>
<KINGSABRI> and yeah native compilation like Golang was great selling point for many project, as much as I understand
Yxhuvud has quit [Remote host closed the connection]
Yxhuvud has joined #crystal-lang
rohitpaulk has joined #crystal-lang
alex`` has quit [Quit: WeeChat 2.0.1]
rohitpaulk has quit [Ping timeout: 240 seconds]
<FromGitter>
<keplersj> @jlebray You're definitely going to want to talk to @faustinoaq. We also have a gitter channel here: https://gitter.im/crystal-scry/Lobby
rohitpaulk has joined #crystal-lang
<FromGitter>
<jlebray> @keplersj Thanks
<FromGitter>
<keplersj> @jlebray Looking at `vim-lsp`'s documentation. I'd have to guess you could get it to work by installing scry to your path and configuring like so:
<FromGitter>
<KINGSABRI> > **<RX14>** @KINGSABRI crystal's package manager is https://github.com/crystal-lang/shards ⏎ ⏎ I mean as repository? because from description "Crystal projects managed by the community" what kind of projects?
<RX14>
mostly shards or tools
<RX14>
like
<RX14>
misc stuff
<RX14>
all sorts
<FromGitter>
<bararchy> @KINGSABRI shards are basically ruby gems, just instead of sitting in the rubygems website they sit in github repos. You can find lots of shards using awesome crystal or using the search site which in turn filter out crystal results
<RX14>
the shards hosting provider bears all the costs
<FromGitter>
<bararchy> randomly found
<FromGitter>
<KINGSABRI> yeah, less cost is a pro, but still couldn't figure no cerntralization is a pro or con
<RX14>
pro
<RX14>
no name squatting
<RX14>
more namespaces
<RX14>
because everything is user/repo
<RX14>
instead of just named
DTZUZO has quit [Ping timeout: 240 seconds]
DTZUZU has quit [Ping timeout: 246 seconds]
<RX14>
and it's easy enough to dump the list from github
<RX14>
which together with awesome-crystal solves discoverability
<RX14>
although it does kinda discriminate against shards hosted on not-github
<FromGitter>
<KINGSABRI> I see, however there's naming duplication possibility, ⏎ in Ruby, there's DNS-Ruby and Ruby-dns because of rubygem we know that but if 2 awesome dudes built a DNS shard then called it DNS.cr then which one is which ?
<RX14>
whichever you put in your shard.yml
<FromGitter>
<KINGSABRI> I see, so I have to know the full url. I can't do like crystall install my-shard
<RX14>
nope
<RX14>
it'd be shards add user/repo
<RX14>
in the normal case of the shard being on github
rohitpaulk has quit [Quit: Ping timeout (120 seconds)]
<RX14>
and it'd fetch the shard at user/repo and then get the same from it's shard.yml and add it to your shard.yml
<FromGitter>
<KINGSABRI> I see
rohitpaulk has joined #crystal-lang
<FromGitter>
<KINGSABRI> I'm sorry, but I remember there was something like ⏎ ⏎ crystal install url-from-github
<FromGitter>
<KINGSABRI> @bararchy I need to install your tool to test it
<FromGitter>
<bew> huh not really
<FromGitter>
<bew> just `git clone ...`
<FromGitter>
<bew> for a shard, you can add it as a dependancy in `shards.yml`, then run `shards install`
<FromGitter>
<KINGSABRI> hmm, @RX14 now that's a con! ⏎ in Go we can just do go get RepoURI
<RX14>
no
<RX14>
in go you add dependencies to your imports
<RX14>
inside the sourcefile
<RX14>
not use go get
<RX14>
go get is for commandline tools
<RX14>
iirc
<FromGitter>
<KINGSABRI> I see your point,
<FromGitter>
<bararchy> @KINGSABRI basically you can do this
Disrecollection has quit [Ping timeout: 248 seconds]
<FromGitter>
<bararchy> @KINGSABRI it's a nice idea, for sqlmap languge agnostic scripting
<FromGitter>
<KINGSABRI> yeah, the maintainer refused to support other languages. The reason was Python is easy to learn and manipulate string. I respect that but some times you need complex processing and your language is your friend regardless which lang you use. so I made an api for that and made proof of concept for many languages even javascript
<FromGitter>
<KINGSABRI> I'll use crystal for speed based applications and I really want to test it's multithreading (I'm sucks already in it)
<FromGitter>
<KINGSABRI> but a first look, it seems Crystal much nicer that Ruby at this part
<FromGitter>
<bew> no multithreading for now, we have concurrency, which works great if you have lot of I/O bounded thing to do
<FromGitter>
<KINGSABRI> yeah, I saw that's but managing threads in general seems nicer, never work with Channels so I've to try it
<RX14>
but you can't use threads in crystal
rohitpaulk has quit [Ping timeout: 260 seconds]
<RX14>
only spawn
<FromGitter>
<KINGSABRI> Aha, so just a subprocess?
<FromGitter>
<bew> no, not process, we have user-space threads, we call them fibers
<FromGitter>
<bew> with `spawn` you can create a fiber and schedule it to execute later
<FromGitter>
<straight-shoota> It's actually even shorter
<FromGitter>
<straight-shoota> I don't understand what you would need Crystagiri for
<FromGitter>
<KINGSABRI> cool, I might need to test both on more complex scenarios ⏎ Thanks @straight-shoota
<FromGitter>
<straight-shoota> Crystagiri just wraps XML, so they do exactly the same thing. It adds a few methods, but IMO that's mostly just bloating the API
<FromGitter>
<bararchy> @straight-shoota good point, maybe it's not really needed
<FromGitter>
<straight-shoota> using `css` selectors instead of xpath is nice, but everything else is not really useful
<FromGitter>
<KINGSABRI> 👍
<FromGitter>
<bew> Also the css selector language is not complete, and you have more precise control with raw xpath
<FromGitter>
<straight-shoota> yes
<FromGitter>
<straight-shoota> but honestly, most use cases don't need such precise control and everyone working with HTML knows CSS selectors
<FromGitter>
<KINGSABRI> Ok, the `io/hexdump` is so sexy thing to me 😍
<FromGitter>
<KINGSABRI> I'm just reading the documentation not even writing code right now
<FromGitter>
<straight-shoota> xpath is obviously better, but I'd have to look up about the complex stuff before using it
<FromGitter>
<bararchy> RX14 it seems to also dynamic link gcc
<RX14>
no
<FromGitter>
<bararchy> in debian
<RX14>
libgcc is like
vivus has left #crystal-lang [#crystal-lang]
<RX14>
part of libc
<FromGitter>
<bararchy> but when you static link something ldd wont show it
<RX14>
@bararchy libcrypto comes from ldd /usr/lib/libevent-2.1.so.6
<RX14>
@bararchy libc isn't statically linked lib
<RX14>
there's libc right in the output right there
rohitpaulk has joined #crystal-lang
<FromGitter>
<bararchy> whats libatomic_ops ?
<RX14>
for libgc
<FromGitter>
<bararchy> and why my example need it and @KINGSABRI doesn't ?
<FromGitter>
<bararchy> beacuse of the static\dynamic thing ?
<RX14>
libatomic_ops is inside the libgc static lib
<RX14>
since it's compiled with libgc
<FromGitter>
<bararchy> oh
<RX14>
note that ldd shows transitive dependencies too
<RX14>
if you did a static link the linker could know what symbols aren't used from the .a file and it'd be smaller than the binary+the size of all the so files
<RX14>
i think at least
<RX14>
hmm
rohitpaulk has quit [Ping timeout: 256 seconds]
<FromGitter>
<KINGSABRI> is there a compilation option for most optimization ?
<RX14>
... --release
<FromGitter>
<KINGSABRI> great , what does `--release` other than the optimization?
<FromGitter>
<bararchy> GCC allows -o 1-3, I think Crystal goes to 3 automatically
<FromGitter>
<bararchy> I meant LLVM
<RX14>
yeah
<RX14>
crystal is just on or off
<RX14>
@KINGSABRI nothing really
<RX14>
--release is just LLVM optimization
<FromGitter>
<straight-shoota> `--release` is just a super fancy switch to disable annoying warnings when using `benchmark`:D
<RX14>
yeah
<RX14>
and its not useful for much else unless you're actually mazing out a CPU
<RX14>
I prefer to deploy --debug in production until the point where I actually need --release mode
<RX14>
since with --debug you get better backtraces
<RX14>
well
<RX14>
not with -d specifically
<RX14>
just leaving off the inlining makes for far better backtraces
<FromGitter>
<KINGSABRI> thanks!
<FromGitter>
<KINGSABRI> another thing, what spawn in Crystal still didn't get the user space thing
<FromGitter>
<KINGSABRI> a question here, why `Channel(TCPSocket).new` not `Channel.new`
<FromGitter>
<bew> because you send a pecific type of object (here `TCPSocket`) through the channel
<FromGitter>
<bew> also, `Channel` is a generic class
<FromGitter>
<KINGSABRI> so `ch` sends `socket` object to `ch` which is basically a `TCPSocket` object through Channel object?
<FromGitter>
<straight-shoota> exactly
<RX14>
socket is a TCPSocket
<FromGitter>
<straight-shoota> `ch.send` puts `socket` on `ch`'s queue and `ch.receive`takes the first item in the queue
<RX14>
ch needs to be a Channel(TCPSocket) because you're sending a TCPSocket through the channel
<FromGitter>
<KINGSABRI> yeah I think I really getting better now and I understand it at least the main idea
<FromGitter>
<KINGSABRI> really it's easier than Threads in Ruby
<RX14>
you could implement Channel in ruby just fine
<RX14>
with locks
<RX14>
fibers aren't easier than threads per se
<RX14>
it's channel that's the real innovation
<FromGitter>
<KINGSABRI> never tried
<RX14>
great thing about crystal is you can read the implementation of channel whenever you want
<RX14>
it probably won't make sense hough
<FromGitter>
<KINGSABRI> channel actually wraps many manual work
<RX14>
since it dives into some of the event loop details
<RX14>
fibers are a speed innovation over threads mainly
<RX14>
channels are an ease of use innovation
<FromGitter>
<KINGSABRI> I see
<FromGitter>
<KINGSABRI> another thing I grepped my attention which is not related to out topic is , `typeof` ⏎ I feel it's a bit ugly and none OOP style. why not `object.type`
<RX14>
well there's 2 concepts
<RX14>
object.class which returns the runtime type of the class
<FromGitter>
<KINGSABRI> like `"Crystal".type`
<RX14>
i.e. what concrete real type is this at the moment
<RX14>
and then there's typeof(object)
<RX14>
which is the type of the variable
<RX14>
the type that the compiler knows
<RX14>
the object can't answer the question of what type the compiler thinks it is
<RX14>
it's not it's job
<RX14>
it can answer what it is specifically
<FromGitter>
<bew> `obj.class` => runtime type
<RX14>
that's why
<FromGitter>
<straight-shoota> typeof receives an expression
<FromGitter>
<KINGSABRI> I see, in Ruby I use `object.class`
<FromGitter>
<straight-shoota> you can't call a method `type` on an expression because it's only a compiler concept
<RX14>
in effect
<RX14>
because runtime type is a property of the object
<RX14>
compile-time type is a property of the variable
<RX14>
when you call methods on a variable you're following the pointer and sending a message to the actual object
<RX14>
(in theorry, not practice)
<RX14>
so it doesn't really make sense to have compile-time type be a method call
rohitpaulk has joined #crystal-lang
<RX14>
@KINGSABRI do you understand the difference between runtime and compile-time type
<FromGitter>
<straight-shoota> an example why you can't just call a method on the value is `typeof(raise "foo")` =)
<FromGitter>
<KINGSABRI> not really, I'm not a core developer. But I code a lot for security related things
<RX14>
@KINGSABRI you need to know this to really be able to code in crystal
<FromGitter>
<KINGSABRI> and Ruby was my first real programming lang
<RX14>
it's a fundamental property of all statically typed languages
<RX14>
I personally think that if you ONLY know ruby then crystal is a really really hard language for rubyists to learn
<RX14>
because crystal is a hard language to learn static typing in
<FromGitter>
<straight-shoota> why do you think it's especially hard?
<RX14>
because it hides the types
<FromGitter>
<straight-shoota> true
<RX14>
you need to KNOW the compile-time types of each variable
<RX14>
in java they're sitting right there
<FromGitter>
<KINGSABRI> I've not issue to learn as much as I enjoy the language, that's why I ran from Go
<RX14>
by the variable definition
<RX14>
in crystal they're hidden
rohitpaulk has quit [Ping timeout: 240 seconds]
<FromGitter>
<straight-shoota> but yes, if you only know a dynamic language like Ruby it's difficult anyway
unknowner has quit [Quit: unknowner]
<FromGitter>
<straight-shoota> at least more difficult than having experience with a statically typed language, say Java
<FromGitter>
<KINGSABRI> I have Basic java knowledge though
<FromGitter>
<KINGSABRI> enough to understand the code and known security issues
<RX14>
well the best way to learn is to do
<RX14>
just start writing crystal and you'll work it out
<FromGitter>
<straight-shoota> an example in java: `Object foo = new Foo()`
return0e has joined #crystal-lang
<FromGitter>
<straight-shoota> a bit simplified, Object is the compile type, Foo the runtime type
<FromGitter>
<straight-shoota> `foo` can have any `Object` as value, but in this case it is assigned an instance of `Foo`
<FromGitter>
<straight-shoota> when executed
<FromGitter>
<KINGSABRI> I see
<FromGitter>
<KINGSABRI> @straight-shoota thanks man it's really fruitful discussion with
<FromGitter>
<KINGSABRI> working with scripting language for long time let you not care about many details
<FromGitter>
<aisrael> This is why am now telling our new hires to learn Crystal first before Ruby. Easier to go that way, then the other way around
<FromGitter>
<bew> Crystal is the new C :p
<FromGitter>
<bew> well to discover static typing at least
<FromGitter>
<KINGSABRI> @bew I hope so I even hope Crystal beats Golang 😎
<FromGitter>
<KINGSABRI> btw, in which case I'll be forced to explicitly use static type with a new object?
<FromGitter>
<KINGSABRI> till now I never static type any object
<FromGitter>
<bew> new languages can coexist I think, no need 'to beat another lang'
<FromGitter>
<KINGSABRI> I mean in speed
<FromGitter>
<aisrael> @KINGSABRI What I love about Crystal (over other, new, statically typed languages) is that it does type inferencing for you. So, no, you don't have to declare types all the time, everywhere
<FromGitter>
<bew> @KINGSABRI you mean when do you need to specify the types? (it's always static typed)
<FromGitter>
<bew> you need to specify types in classes for the instance variables
<FromGitter>
<KINGSABRI> @aisrael thanks ⏎ @bew in variable declaration for example, I don't static type till now
<FromGitter>
<bew> for local variable you never need them (I never needed them)
<FromGitter>
<aisrael> There are some cases when the compiler can't infer the type of something, so it'll complain and you have to specify it. In most cases, though, I consider it a best practice to add the type annotations. In some cases thoug, it makes your method more 'generic'
<FromGitter>
<aisrael> @bew is right. I don't ever recall declaring local var types
<FromGitter>
<aisrael> I like to declare method return types (added safety e.g. if I forget a possible `nil` return path)
<FromGitter>
<KINGSABRI> I see
return0e has quit [Ping timeout: 264 seconds]
<FromGitter>
<KINGSABRI> guys, don't you think `Lazy` is important to `Enumerable` ?
<FromGitter>
<bew> what do you mean be `Lazy`?
<FromGitter>
<KINGSABRI> in Ruby, there is lazy enumerator I generally use to not load a hole file I want to readlines it
<FromGitter>
<bew> you mean an iterator maybe?
return0e has joined #crystal-lang
<FromGitter>
<KINGSABRI> it's enumerator
<FromGitter>
<KINGSABRI> eg. `File.readlines('/etc/passwd')` this will directly loads the etc/passwd in an array ⏎ but when you do `File.readlines('/etc/passwd').lazy` it returns Enumerator::Lazy
<FromGitter>
<bew> for example, in case of a file (or any IO objects), `IO#each_line` will return an iterator that will lazily consume the IO as needed
<FromGitter>
<KINGSABRI> @bew each_line requires the file to be loaded so you have to `File.open('/etc/passwd').each_line` so the file is open and loaded already
<FromGitter>
<bew> open doesn't mean loaded
<FromGitter>
<bew> or read
<FromGitter>
<KINGSABRI> `#lazy` helps me in huge files
<FromGitter>
<KINGSABRI> yes I mean read
<FromGitter>
<bew> `File.open` won't read anything from the file
<FromGitter>
<bew> just creates a `File` object, that you can read/write from/to
<FromGitter>
<KINGSABRI> yeah, I just checked that, you're right