jhass changed the topic of #crystal-lang to: The Crystal programming language | https://crystal-lang.org | Crystal 0.35.1 | Fund Crystal's development: https://crystal-lang.org/sponsors | GH: https://github.com/crystal-lang/crystal | Docs: https://crystal-lang.org/docs | Gitter: https://gitter.im/crystal-lang/crystal
<oprypin> crsfml is freakin amazing, no idea why people arent making awesome games with it
MasterdonX has joined #crystal-lang
oddp has quit [Ping timeout: 244 seconds]
rocx has joined #crystal-lang
jesfre has quit [Ping timeout: 240 seconds]
f1refly has joined #crystal-lang
f1reflyylmao has quit [Ping timeout: 260 seconds]
Munto has joined #crystal-lang
jesfre has joined #crystal-lang
duane has quit [Ping timeout: 240 seconds]
dostoyevsky has quit [Quit: leaving]
dostoyevsky has joined #crystal-lang
alexherbo2 has joined #crystal-lang
jesfre has quit [Ping timeout: 240 seconds]
alexherbo2 has quit [Quit: Ping timeout (120 seconds)]
alexherbo2 has joined #crystal-lang
dostoyevsky has quit [Quit: leaving]
dostoyevsky has joined #crystal-lang
Vexatos has quit [Quit: ZNC Quit]
Vexatos has joined #crystal-lang
<FromGitter> <mavu> Does anyone know if there is somekind of activeRecord in crystal that I can include in a class based on DB?
<FromGitter> <mavu> wait, i have not even tried googling activerecord crystal lang. brb
<FromGitter> <mavu> jennifer maybe?
oddp has joined #crystal-lang
f1reflyylmao has joined #crystal-lang
f1refly has quit [Ping timeout: 260 seconds]
Elouin has quit [Read error: Connection reset by peer]
Elouin has joined #crystal-lang
<raz> yup, i'm using jennifer and quite happy with it (docs are a bit rough, but it all works as advertised)
<raz> there are also clear, granite, avram and perhaps others to look at
<raz> (personally i'm also very fond of crecto, but last i checked it sadly looked unmaintained)
masterdonx2 has joined #crystal-lang
MasterdonX has quit [Ping timeout: 246 seconds]
<FromGitter> <j8r> raz: to serialize any object out of the box: https://github.com/j8r/crystalizer ;)
<FromGitter> <j8r> Is it planned to have a central place/shard which support the most libc bindings possible?
<FromGitter> <j8r> I need statfs to have disk usage, on some others.
<FromGitter> <anapsix> greetings, oh wizards of Crystal! ⏎ I'm new in your realm, and trying to navigate it's many wonders.. ⏎ I find myself in Macro land, and struggling to figure out a way of passing a variable (String) to the macro which takes arguments. ⏎ ⏎ Using example from issue 949 (https://github.com/crystal-lang/crystal/issues/949) ... [https://gitter.im/crystal-lang/crystal?at=5f197d4b6279c91f420a36d6]
lanodan has quit [Ping timeout: 260 seconds]
<FromGitter> <Blacksmoke16> pretty sure you're trying to call `.split ` on `a`, like the word `a` not its value
<FromGitter> <Blacksmoke16> you cant use runtime variables with a macro @anapsix
<FromGitter> <Blacksmoke16> what are you trying to do?
duane has joined #crystal-lang
<FromGitter> <anapsix> Hi @Blacksmoke16 :) found my way here, rather than bother you personally ⏎ I'm trying to call appropriate `Class.new()`, based on the variable (read from YAML) ⏎ Kinda like a way to create an object from specific class, depending on the config
<FromGitter> <Blacksmoke16> thats not going to be trivial i think
<FromGitter> <Blacksmoke16> are these arbitrary classes?
<FromGitter> <anapsix> guess, I need to look closer at existing routing examples in various projects.. ⏎ I think, they do something similar
<FromGitter> <Blacksmoke16> you working on a web framework? :P
<FromGitter> <anapsix> > are these arbitrary classes? ⏎ ⏎ well, not entirely arbitrary ⏎ there are those that are implemented, all are child classes of a parent abstract class [https://gitter.im/crystal-lang/crystal?at=5f19865ff583a47d15a80300]
<FromGitter> <Blacksmoke16> possibly could look into https://crystal-lang.org/api/master/YAML/Serializable.html#use_yaml_discriminator(field,mapping)-macro
<FromGitter> <Blacksmoke16> would get you the instance, but wouldnt handle knowing what method to call
<FromGitter> <anapsix> > you working on a web framework? :P ⏎ ⏎ nah.. making a build system, sort of
<FromGitter> <Blacksmoke16> gotcha
lanodan has joined #crystal-lang
<FromGitter> <anapsix> that might work, since all abstract class children would implement same methods
<FromGitter> <Blacksmoke16> 👍
<FromGitter> <anapsix> thank you, again)
<FromGitter> <Blacksmoke16> if the user is able to define their own classes prob wont work to well tho, as the type to class mapping is static on the abstract type
<FromGitter> <anapsix> I'll settle for having to recompile for now ⏎ being able to specify "plugins / modules" dynamically, from project configuration would be awesome though
<FromGitter> <Blacksmoke16> i more so meant the user would have to reopen the type and add their types, including the built in ones
<FromGitter> <Blacksmoke16> if you're coming from ruby it might be worth to rethink how you want to do things as doing stuff as dynamically as Ruby can is going to not be trivial (if at all possible)
duane has quit [Ping timeout: 256 seconds]
<raz> j8r: yay, yap, that looks more approachable to me :D don't have a need for it atm but i probably will at some point
<FromGitter> <anapsix> > if you're coming from ruby it might be worth to rethink how you want to do things as doing stuff as dynamically as Ruby can is going to not be trivial (if at all possible) ⏎ ⏎ yeah, I'm getting that vibe. It's hard to switch from Ruby way of thinking
HumanG33k has joined #crystal-lang
HumanG33k has quit [Remote host closed the connection]
<raz> ruby -> crystal learning curve is a stair-step shape. first you try to do it the ruby way and it kinda works but feels sorta off in some ways. then eventually it clicks and the enlightenment kicks in. somewhere around that point it also starts becoming painful to go back to ruby ("jeez, has it really always been this slow?", "ugh, in crystal this typo would've been caught by the compiler...")
HumanG33k has joined #crystal-lang
<raz> while starting out the most rewarding thing for me was to port many of my little batch-processing/helper scripts from ruby to crystal. the first one is annoying ("ugh, why can't i just JSON.parse"). but then it runs, and boy does it run fast...
<FromGitter> <anapsix> yep yep @raz.. I'm starting off in Crystal land by making cli utilities. And it's so awesome to be able to make a static binary that works without having to install the interpreter, and bunch of dependencies
<raz> yup, can only second that. distributing ruby apps is a royal pain.
<FromGitter> <wyhaines> At the same time, re the learning curve, one of the great things about Crystal, from an adoption POV, is that a Rubyist can become productive with Crystal very quickly. A Rubyist learning Go or Rust has a very limited amount of knowledge that will directly transfer. But a Rubyist can look at Crystal code, and even without really knowing how the type system works, they will be able to basically understand the
<FromGitter> ... code. A Rubyist with just a modicum of training will be able to make bug fixes and improvements on existing code, and after a little exposure, mostly to the nuances of typing and to the idiomatic differences between the two languages, as well as exposure to how to do some of the more common dynamic Ruby things, they will re ... [https://gitter.im/crystal-lang/crystal?at=5f19949ff0b3335ce18b91be]
sorcus has quit [Ping timeout: 260 seconds]
sagax has quit [Read error: Connection reset by peer]
Human_G33k has joined #crystal-lang
HumanG33k has quit [Ping timeout: 240 seconds]
<FromGitter> <wontruefree> @anapsix I am curious what the you ran into transitioning from Ruby to Crystal. I have been in the Crystal community too long to know what my first struggles were
<FromGitter> <neutrinog> does anyone know how to execute a bash command from within crystal?
<FromGitter> <Blacksmoke16> https://crystal-lang.org/api/master/toplevel.html#system(command:String,args=nil):Bool-class-method ?
<FromGitter> <j8r> @neutrinog Or Process.run
<FromGitter> <neutrinog> Process.run hates me :(
<FromGitter> <neutrinog> `Process.run("echo 'hi'")` produces `Unhandled exception: Error executing process: 'echo 'hi'': No such file or directory ....`
<FromGitter> <Blacksmoke16> try with https://crystal-lang.org/api/master/toplevel.html#%60(command):String-class-method
<FromGitter> <neutrinog> so i was second guessing whether that was the proper way to execute a command. Also, I'd like to get the output if possible.
<FromGitter> <neutrinog> @Blacksmoke16 that's perfect. and way simpler. thanks.
<FromGitter> <Blacksmoke16> 👍
<FromGitter> <wontruefree> @neutrinog I think there is some escaping and safety in `Process.run` you can pass in an array for the args. `Process.run("echo", ["'hi'"])`
<FromGitter> <neutrinog> does process provide to stdout?
<FromGitter> <wontruefree> it returns the status of the command but you can use the block form to get stdout https://crystal-lang.org/api/0.35.1/Process.html#run(command:String,args=nil,env:Env=nil,clear_env:Bool=false,shell:Bool=false,input:Stdio=Redirect::Pipe,output:Stdio=Redirect::Pipe,error:Stdio=Redirect::Pipe,chdir:String?=nil,&)-class-method
<FromGitter> <wontruefree> I take that back it looks like you pass it the output io
<FromGitter> <wontruefree> I think you can use `\`\`` if you want to run a command and get the output `echo "hi"`
<FromGitter> <neutrinog> using ` worked fine.
<FromGitter> <neutrinog> in my case there won't be any external args so I'm not too worried about sanitation.
<FromGitter> <j8r> do you really need bash then?
<FromGitter> <neutrinog> I'm inspecting the status of a docker container.
<FromGitter> <neutrinog> and if it's not running I'll start it.
<FromGitter> <j8r> if you are using a binary, no need to use bash
<FromGitter> <wontruefree> sounds like a schrodinger container
<FromGitter> <neutrinog> lol. I don't even know what that is @wontruefree
<FromGitter> <j8r> like, `Process.run "/usr/bin/docker"`?
<FromGitter> <wontruefree> it was a bad joke. https://en.wikipedia.org/wiki/Schr%C3%B6dinger%27s_cat
<FromGitter> <neutrinog> 😄
<FromGitter> <neutrinog> @j8r I don't see the benefit over using `.
<FromGitter> <Blacksmoke16> hes saying you could just execute the commands your bash script is in crystal, then you dont need bash
<FromGitter> <neutrinog> oh ok. Sorry I was using terms incorrectly. I'm not executing a bash script. Just a "bashy" command? I just associate anything that can run on the command line as bash code. lol.
<FromGitter> <j8r> @neutrinog more robust, and faster. And maybe the exist status better
<FromGitter> <j8r> an interpreter /bin/sh is spawn
<FromGitter> <j8r> but Crystal, as Bash, or most any language, can call a binary. ⏎ So: Crystal -> Binary, instead of Crystal -> Bash -> Binary
<FromGitter> <j8r> btw, this makes also your application easily portable to Windows - if needed
<FromGitter> <neutrinog> oh yeah.. I forget about that one sometimes. 😉
duane has joined #crystal-lang
<FromGitter> <neutrinog> Cool figured out the Process implementation. thanks for the comparison.
<FromGitter> <anapsix> > @anapsix I am curious what the you ran into transitioning from Ruby to Crystal. I have been in the Crystal community too long to know what my first struggles were ⏎ ⏎ @wontruefree very much in a process of learning and trying to grasp the new concepts ⏎ type of variables is first thing that pops out.. e.g. the output of `YAML.parse()`is `YAML::Any`, and so is the value of it's keys ⏎ having to deal
<FromGitter> ... with Nillables, ugh.. ... [https://gitter.im/crystal-lang/crystal?at=5f19b73c15e5e72fb36f8dbd]
<FromGitter> <anapsix> I find the Crystal Book very helpful, but some examples actually use class overloading.. sort of.. if you're following in ICR
<FromGitter> <anapsix> I wish it would contain more examples and common patterns, which would be helpful coming from dynamic language
<FromGitter> <Blacksmoke16> i assume you know about the API docs as well?
<FromGitter> <anapsix> I suppose, PRs are welcome
<FromGitter> <anapsix> yep, API doc is open in the next tab over
<FromGitter> <Blacksmoke16> > having to deal with Nillables, ugh.. ⏎ ⏎ This forces you to think about the types of your stuff. I.e. does this actually need to be nilable? Is there a way to refactor something so I can handle nils at a higher level? etc
<FromGitter> <anapsix> ah, wonderful
<FromGitter> <anapsix> I can't tell how many times I've closed ICR with CTRL+C :P
<FromGitter> <anapsix> (by accident)
<FromGitter> <Blacksmoke16> i find it easier to just have a `test.cr` file
<FromGitter> <Blacksmoke16> be pretty easy to setup `nodemon` to rerun it on save too
<FromGitter> <Blacksmoke16> then you dont have to deal with the limitations of icr
sagax has joined #crystal-lang
<FromGitter> <anapsix> yeah.. and you can do more with macros, since ICR wraps things in certain ways
<FromGitter> <wontruefree> @anapsix that is good to know. So to distill it down... nil, return types, macro magic, and patterns ?
<FromGitter> <Blacksmoke16> if you're just starting out macros might not be the best idea
<FromGitter> <Blacksmoke16> its deff a more advanced concept
<FromGitter> <wontruefree> agreed
<FromGitter> <Blacksmoke16> they have use cases, but its not just like "throw macros at the problem until its fixed" there is probably a better way to handle it
alexherbo2 has quit [Ping timeout: 240 seconds]
<FromGitter> <anapsix> it's like with explosives, or regex.. almost any problem can be solved with those ;)
alexherbo2 has joined #crystal-lang
alexherbo2 has quit [Ping timeout: 264 seconds]
<FromGitter> <wyhaines> Someone asked about some of the gotchas when coming from Ruby to Crystal. I've given a couple of presentations of Crystal for Rubyists, and one of the idiomatic things that has stuck out to me about that transition is the use of overloading. In Ruby we just have to put sometimes complicated argument handling at the top of a method if that method is intended to work with a variety of different possible inputs.
<FromGitter> ... ⏎ ⏎ As a Rubyist coming to Crystal, that is a hard habit to break, and most of the time one can make it work through type unions, type inspection, and type casting. ⏎ ⏎ But it is SO MUCH easier and simpler to use overloading to just explicitly define the different contracts that the method has with it's users, and then ... [https://gitter.im/crystal-lang/crystal?at=5f19cc9d15e5e72fb36fc788]
alexherbo2 has joined #crystal-lang
<FromGitter> <RespiteSage> Has anyone else had issues with including a module at multiple levels of a type hierarchy?
alexherbo28 has joined #crystal-lang
<FromGitter> <RespiteSage> I'm trying to reduce this a little, but this is a really weird issue that a coworker of mine had: https://play.crystal-lang.org/#/r/9g44 vs https://play.crystal-lang.org/#/r/9g3w.
<FromGitter> <anapsix> > @anapsix that is good to know. So to distill it down... nil, return types, macro magic, and patterns ? ⏎ ⏎ @wontruefree I suppose, you can add annotations to that list of magical Crystal things ⏎ I'm sure there is more.. it's hard to formulate things which are still flying around in my head, unsettled [https://gitter.im/crystal-lang/crystal?at=5f19ceea273e723b7ffdea09]
alexherbo2 has quit [Ping timeout: 240 seconds]
alexherbo28 is now known as alexherbo2
alexherbo2 has quit [Ping timeout: 265 seconds]
<bougyman> Ok, stupid new user question here. Just installed icr from shards.yml... where did it install to/
<FromGitter> <wontruefree> good thing to add
<FromGitter> <wontruefree> I just was curious
alexherbo2 has joined #crystal-lang
<FromGitter> <Blacksmoke16> bougyman: `./bin`?
alexherbo24 has joined #crystal-lang
alexherbo2 has quit [Ping timeout: 240 seconds]
alexherbo24 is now known as alexherbo2
<FromGitter> <Blacksmoke16> annotations rely heavily on macros, so id put them in that same bucket
<FromGitter> <ShalokShalom> Any recommendations for tutorials and stuff like that, when it comes to Crystal as a first language?
<FromGitter> <Blacksmoke16> API Docs and the book are prob your best bet
<FromGitter> <ShalokShalom> I know the basics, while I would need something to take me at my hands and guides me through the first projects.
<FromGitter> <anapsix> I found reading Amber / Granite code very interesting and challenging: https://github.com/amberframework/granite/
<FromGitter> <Blacksmoke16> 😬 :P
<FromGitter> <ShalokShalom> You really think the API documentation is useful for somebody new to programming?
<FromGitter> <Blacksmoke16> i mean yea, it lists all the methods on a given type, usually with examples etc
<FromGitter> <ShalokShalom> And this teaches programming?
<FromGitter> <Blacksmoke16> not really, its a resource not a guide
<FromGitter> <Blacksmoke16> like "i want to make this string all uppercase" go to API docs, go to `String` type, and ctrl+f for `upper` and you'll prob find your answer
<FromGitter> <ShalokShalom> I look for some guide
<FromGitter> <ShalokShalom> I dont even know why I should make a string go all uppercase
<FromGitter> <ShalokShalom> Since I am missing the context.
<FromGitter> <Blacksmoke16> programming is mostly open ended. Guides can teach you the syntax and patterns for solving a problem but chances are you wont find a guide for everything you need to do
<FromGitter> <Blacksmoke16> so the context is whatever problem you're trying to solve
<FromGitter> <Blacksmoke16> is there something specific you're trying to do?
alexherbo22 has joined #crystal-lang
alexherbo2 has quit [Ping timeout: 264 seconds]
alexherbo22 is now known as alexherbo2
sorcus has joined #crystal-lang
<raz> as much as i hate to say it, but crystal might not be the best first-language, yet
<raz> (just cause it uses fairly advanced concepts and afaik there are not many beginner tutorials written yet)
<FromGitter> <HCLarsen> Crystal is by far my favourite language, however, I'll agree that it's not a good beginner language.
<raz> yup, although in fairness, i also wouldn't be sure which language to really suggest as a first
<raz> certainly not javascript...
<FromGitter> <HCLarsen> I'd suggest Ruby. I think it'd make a great first language.
<FromGitter> <HCLarsen> JavaScript sucks. And I say that as someone who's paid to write JS.
<raz> yup ruby might be good. but probably also to wrap your head around things like blocks right off the bat
<FromGitter> <HCLarsen> I started with QBASIC, way back in the day. In hindsight, the simplicity of the syntax and lack of strong typing made it easy for me to learn.
<FromGitter> <HCLarsen> After a year of it, I graduated to C. Having the basics in mind already, it was easy for me to move into a statically typed language.
<raz> yea. some basic-like language would probably be best. the common suggestions i see from people are javascript ("easy to see quick results") or python ("so easy"). but i strongly disagree with that. imho they rot the brain.
<raz> it's so hard to unlearn these broken concepts
<FromGitter> <HCLarsen> I think Python sucks more than JavaScript. The whole open ended blocks is just so pointless.
<FromGitter> <HCLarsen> Plus, if a beginner gets into that habit, it'll be hard to break.
<raz> yeh don't even get me started on python :D
<raz> lua could be awesome, if they hadn't screwed up the fundamentals so badly (counting from 1)
<FromGitter> <HCLarsen> Ruby is actually very basic-like in it's presentation. The beauty of it is that you can do so much more with it than you can with BASIC.
<FromGitter> <HCLarsen> My lua knowledge is very limited, so I can't comment on that.
<FromGitter> <Blacksmoke16> Crystal would be good, but look at Ruby tutorials and do them in crystal
<FromGitter> <tenebrousedge> Ruby is BASIC-like? oy vey
<raz> well, i think the good part about ruby for a beginner is its consistency (as opposed to something like python)
<FromGitter> <HCLarsen> @tenebrousedge very straight forward syntax. That's what I'm referring to.
<FromGitter> <Blacksmoke16> Otherwise you end up with a dynamic mindset
<raz> but stuff like blocks will be a huge learning barrier and ruby uses them everywhere
<FromGitter> <HCLarsen> @Blacksmoke16 see my comment about my early learning path. It's easy to move from a dynamic to a static mindset once you grasp the other programming concepts.
<raz> also the whole symbol vs string nonsense
<FromGitter> <HCLarsen> Yeah, but you can avoid using symbols if you want.
<FromGitter> <HCLarsen> I write Ruby all the time, and I've hardly ever used symbols.
<raz> yeh but as a beginner you have to understand them before you can avoid them ;)
<FromGitter> <HCLarsen> Not really. They're just syntactic sugar. You don't even need to know about them to do most things with Ruby.
<raz> actually, thinking about it, i guess golang is a good learning language. probably actually a major reason why it's successful. it puts you in a very tight straightjacket, just what beginners (and cheap corporate wage-slaves) need
<raz> but it would feel almost cruel to me to suggest someone to learn it
<FromGitter> <HCLarsen> It's backed by Google, that's reason enough not to use it.
<raz> i don't care about the backing. i just find it intolerable to read or write
<FromGitter> <tenebrousedge> the best about golang is that errors are values. That's also the worst part of golang
<raz> the aesthetics alone are just gross to me. i can't think of a language that looks uglier to me on a screen even without reading the words
<oprypin> HCLarsen, no its actually just bad, you dont need such secondary blanket criteria
<FromGitter> <HCLarsen> @FromIRC oprypin, I'm not sure what you're referring to.
<FromGitter> <HCLarsen> oprypin, I'm not sure what you're referring to with that comment.
<oprypin> >> golang >> It's backed by Google, that's reason enough not to use it.
<DeBot> oprypin: Error: unterminated char literal, use double quotes for strings - https://carc.in/#/r/9g53
<oprypin> lol
<raz> haha
<raz> i don't like google much either. but language-wise their backing is actually a pro for me. i mean go is huge, well documented etc. because of google.
<FromGitter> <HCLarsen> Ok. I've never looked at Go, and don't much intend to.
<oprypin> c++ is literally easier to use than go lol
<oprypin> sure, you need to know a lot more to get to that point but yea
<raz> yeh i dunno. if i want stupid fast and sharp edges, why not rust
<FromGitter> <HCLarsen> I don't mind c++. I haven't done a lot with it, but I learned a little bit of it back in 97.
<raz> i've done enough c++ to avoid it for its footguns
<oprypin> if it was before ease 2013 it doesnt count
<oprypin> if it was before year 2013 it doesnt count
<oprypin> dont know how i mistyped that
<FromGitter> <HCLarsen> Most of my programming life was before 2013.
renich has joined #crystal-lang
deavmi has quit [Read error: Connection reset by peer]
deavmi has joined #crystal-lang
<FromGitter> <j8r> Shell can be a good introduction to
<FromGitter> <j8r> Programming. Some people does not know at all what is possible to gain in time
<FromGitter> <j8r> Obviously shell is not well designed, but for simple if condition it is ok. Plus, we also learn Unix basics usually at the same time
alexherbo2 has quit [Quit: Ping timeout (120 seconds)]
alexherbo2 has joined #crystal-lang
<FromGitter> <j8r> oprypin, you are not very corporate! :)
<FromGitter> <j8r> Ha you were quoting @HCLarsen , sorry 😅
Elouin has quit [Read error: Connection reset by peer]
Elouin has joined #crystal-lang