<crystal-gh>
[crystal] jwoertink opened pull request #6453: rename alias HTTP::Handler::Proc to HTTP::Handler::HandlerProc (master...pr-6386) https://git.io/fNugT
<FromGitter>
<bew> what kind of modification you're thinking about?
<FromGitter>
<Blacksmoke16> removing a key
<FromGitter>
<bew> huh an array doesn't have any key, I don't get it
duane has joined #crystal-lang
<FromGitter>
<Blacksmoke16> no i mean i have an array of objects
<FromGitter>
<Blacksmoke16> like `Array(Foo)`
<FromGitter>
<Blacksmoke16> where the output could look like
<FromGitter>
<drinkmorewaters> Can anyone tell me if these are the same, as i am taking Javacript code and trying to replicate the results in Crystal. I believe this is called a "Constructor"
<FromGitter>
<drinkmorewaters> Feels like i did it wrong as the Crystal code is much faster and a hell of a lot smaller/cleaner.
<FromGitter>
<DanilaFe> Well, you're not creating anything like a "class". You're just calling a function.
<FromGitter>
<drinkmorewaters> Also, is there a reason why Javascript allows functions within functions but Crystal seems to not like a function within a function.
<FromGitter>
<drinkmorewaters> @sam0x17 Is there a reason why Crystal would choose not to follow that pattern? Does it create a headache?
jokke1 has quit [Ping timeout: 256 seconds]
<FromGitter>
<DanilaFe> Crystal is a compiled language, so I imagine nested functions are a lot more of a headache
jokke1 has joined #crystal-lang
<FromGitter>
<DanilaFe> You can get pretty close with blocks and procs (closures, which are the same as JS functions if I remember correctly)
<FromGitter>
<drinkmorewaters> Also is a struct in Crystal similar to a struct in Ruby?
<FromGitter>
<sam0x17> @drinkmorewaters yes javascript is a very different language since it is dynamic you can do things that would be illegal in crystal. Ruby is also dynamic, but it uses proper object oriented patterns instead of javascript where you can literally type this.whatever or some_object.whatever and assign them to whatever you like on the fly (which can lead to super dangerous / hard to catch errors)
<FromGitter>
<sam0x17> because crystal is compiled, all the types and everything have to check out at compile time, so that is why it is more picky, but it is so, so worth it
<FromGitter>
<DanilaFe> Well, JavaScript is weird because every object is just a key / hash
<FromGitter>
<bew> @drinkmorewaters a struct in Crystal is 'almost' like a class, but allocated on the stack (whereas classes are allocated on the heap)
<FromGitter>
<sam0x17> yeah that's a better way of thinking of it basically everything in javascript is a hash
<FromGitter>
<drinkmorewaters> So in the end, i'll probably shoot myself in the foot by following Javascript as a guideline lol.
<FromGitter>
<DanilaFe> You can shoot yourself in the foot using JavaScript by itself
<FromGitter>
<drinkmorewaters> Would it be better to reference another typed language such as Go to do comparisons?
<FromGitter>
<sam0x17> ruby would probably be the best
<FromGitter>
<sam0x17> we get a lot of ruby questions
<FromGitter>
<sam0x17> as in people coming from ruby
<FromGitter>
<drinkmorewaters> I am reading about Ruby structs and classes but it's not easy as they do have slight differences that i cannot workout as of yet.
<FromGitter>
<sam0x17> its a totally different thing in ruby
<FromGitter>
<sam0x17> in ruby Struct is a convenience class that lets you create DSLs easily because you can define an entire hierarchy of objects without writing a bunch of classes
<FromGitter>
<sam0x17> like how javascript lets you just assign random properties willy nilly, Struct in ruby sort of lets you do that
<FromGitter>
<sam0x17> in crystal, a Struct is totally unrelated to that
<FromGitter>
<bew> reading about it, a ruby struct is just a way to easily generate a class with some fields
<FromGitter>
<sam0x17> yup
<FromGitter>
<bew> kinda like `record` here in crystal (but it generates immutable Crystal struct)
<FromGitter>
<drinkmorewaters> Ok, so much more structured. I just can't find it out without some sort of tutorial at the moment.
<FromGitter>
<drinkmorewaters> Yeah it's in no way meant for beginners.
<FromGitter>
<sam0x17> you basically want to learn the difference between passing by value and passing by reference , which is a concept especially prevalent in C++
<FromGitter>
<sam0x17> have you ever used Java? I can explain it in a java sort of way
<FromGitter>
<drinkmorewaters> I've not used any languages, this is my first week, i want to learn Crystal but i'm probably making a mistake as i'm hitting wall after wall.
<FromGitter>
<drinkmorewaters> Just because my enthusiasm outpaces the amount of content available.
<FromGitter>
<icyleaf> You need learn only one language, be focus!
<FromGitter>
<bew> may I ask why you're so enthusiast about Crystal even though you don't know well any language? (that's what I understood from you at least)
<FromGitter>
<sam0x17> this is interesting to me because I plan to introduce my 11 year old nephew next week to programming via crystal
<FromGitter>
<sam0x17> in all honesty you could just use classes for now and ignore structs until you have time to come back later and understand them. You can totally get by without them
<FromGitter>
<drinkmorewaters> @bew Speed, simplicity, structure (Types) safety, compiled (much easier than Ruby to figure out what went wrong, portable binary.
<FromGitter>
<drinkmorewaters> @bew new frameworks, not as bloated, if i start now i can get a better understanding, Rails 5 is so large and has so much stuff that i feel bogged down almost instantly.
<FromGitter>
<bew> interesting ;)
<FromGitter>
<drinkmorewaters> @sam0x17 Ok, i'll checkout classes too and how to work with them.
akaiiro has quit [Ping timeout: 268 seconds]
<FromGitter>
<bew> @sam0x17 awesome! you may have a hard time explaining the errors from the compiler to you nephew though ^^
<FromGitter>
<sam0x17> @drinkmorewaters if you dont mind me asking, what sort of background are you coming to programming from?
Raimondi has quit [Remote host closed the connection]
<FromGitter>
<DanilaFe> I feel like Crystal errors are pretty good, but the trace for them is very long and verbose
<FromGitter>
<bew> is it its 1st programming language? @sam0x17
<FromGitter>
<sam0x17> yes he's messed around with some sort of "programming" at school but it was probably that blocks thing or whatever its called
<FromGitter>
<bew> scratch..
<FromGitter>
<sam0x17> yes that
<FromGitter>
<drinkmorewaters> @bew Is that a decent enough answer? People learnt Ruby as their first language, i can't see why Crystal would be more complex, considering it puts more contraints in place to fix errors? ⏎ @sam0x17 I was doing Shopify stores, front end design, i wanted to know more about what was happening, i knew no Javascript or any language, i want to build things for myself. Or maybe just understand tech to
<FromGitter>
... better guide my future, as everything will be based on tech. ⏎ ⏎ If i am too be honest, would you recommend i scrap Crystal until theirs more beginners stuff and just stick to Javascript, Ruby or Python (The one everyone recommends) [https://gitter.im/crystal-lang/crystal?at=5b5ab7775301255724caebcd]
<FromGitter>
<sam0x17> he's very motivated since he has terrible internet in his area so this is his only chance at fun lolol
<FromGitter>
<sam0x17> @drinkmorewaters ok so you're a frontend developer... did you do HTML markup or strictly photoshop type stuff
<FromGitter>
<bew> very cool Sam!!
<FromGitter>
<drinkmorewaters> I know HTML, CSS but absolutely no JS i was able to style Shopify stores but not do something like, connect to the graphql api or something more fun.
<FromGitter>
<bew> @drinkmorewaters I have no idea, I personally started with C a long time ago so I can't really compare to my experience ^^
<FromGitter>
<drinkmorewaters> The reason i chose Crystal is because it's newer i could get in at the start and have a better understanding. Javascript has so much churn. Which made me feel i would constantly be chasing.
<FromGitter>
<drinkmorewaters> @bew Lol, i'm not going anywhere near C or C++ haha
<FromGitter>
<DanilaFe> The benefit of old languages is that there's a LOT of examples / documentation / tutorials
<FromGitter>
<sam0x17> @drinkmorewaters ok so in that case, you definitely should learn js at some point. I recommend learning pure js and then some jquery before you try using any frameworks. For server side it doesn't really matter what you learn and you are saying all the right reasons for wanting crystal so I say stick with crystal
<FromGitter>
<DanilaFe> That isn't to say you shouldn't use crystal, it's great
<FromGitter>
<drinkmorewaters> @DanilaFe Absolutely, that's definitely something that would help me immensely but i am worried, i spend that time learning that i would have been better off on the one that i kept gravitating towards lol
<FromGitter>
<sam0x17> technically speaking, you would get the most mileage out of learning js and doing node.js/express for server side, but I advise against this because npm is so terrible and broken and the js ecosystem is fragmented af and glitchy af and trust me you don't want to deal with that
<FromGitter>
<drinkmorewaters> @sam0x17 I know enough Jquery to be dangerous, but not enough to be useful haha. I don't know what i'm doing when i do it.
<FromGitter>
<drinkmorewaters> @sam0x17 Yeah, the only reason i didn't go with JS and node is that even the Node creator canned it, people like TJ dropped node for GO and WASM soon, i am gauging that if the pros moved on, then well.
<FromGitter>
<sam0x17> @drinkmorewaters at a certain point you will realize no one knows what they are doing, and "conventions" and the things frameworks do are just people being confident and asserting that "this is a good way to do x" -- this is something I often tell the junior developers I train because they come in all wide-eyed thinking they know nothing when really they already know quite a bit they just aren't
<FromGitter>
... arrogant/confident/whatever enough to hack things into working (which is what everyone does)
<FromGitter>
<sam0x17> being a developer is mostly about being unafraid to mess around with things until they work, and trying things out that might break, imo, and it takes a certain confidence
<FromGitter>
<sam0x17> yeah totally agree on compiled languages / go / wasm / etc .. I am banking on crystal having web assembly support and doing 100% of my work in crystal lolol
<FromGitter>
<bew> nice way to put it, I've realized it not too long ago, and was thinking about it lately,so at least I'm not crazy :p
<FromGitter>
<sam0x17> yeah, its so a thing
<FromGitter>
<sam0x17> lol
<FromGitter>
<drinkmorewaters> @sam0x17 I want to hack shit together for fun and have it be portable, maybe leverage wasm via LLVM (Crystal) be portable (Crystal) and be fast as heck (Crystal) So i think i got the right language, just go no idea how to get some fun things together. I've been hacking away with Lucky and Amber, doing pretty useless stuff. But it's the core concepts that i can't translate from Ruby or another langauge
<FromGitter>
... as it just doesn't work that way it seems.
<FromGitter>
<sam0x17> @drinkmorewaters there is no better teacher than a project with a deadline, but in lieu of that you should pick some sort of goal/project to create with crystal, could be anything
<FromGitter>
<bew> if it's your first compiled (and static typed) language, it's definitely quite different from what you know from other interpreted languages
<FromGitter>
<DanilaFe> Try to make something simple, like fizzbuzz, or maybe a pig latin converter
<FromGitter>
<sam0x17> or a terminal program that tells you the weather (scrape it from weather.com or whatever) and uses a YAML file to configure your location and other things. (just a suggestion)
<FromGitter>
<DanilaFe> No need to scrape, there's always openweathermap
<FromGitter>
<drinkmorewaters> I'm not struggling to come up with ideas, that parts fine, i'm struggling to find examples, tutorials or explanations to help with the gotchas, the learning and the methods i want to do.
<FromGitter>
<sam0x17> lol I'm that guy who still scrapes rather than learning yet another REST API
<FromGitter>
<DanilaFe> With crystal's from_json or whatever it's called, most of the API stuff is easy
<FromGitter>
<drinkmorewaters> So i am spending double time looking at another language and trying to replicate it, with wild results lol I'm trying to be a translator without knowing either language, it's quite stupid.
<FromGitter>
<sam0x17> no that makes sense, at least you have this chat though
<FromGitter>
<sam0x17> getting a good idea of what these other languages do will help you gain perspective on how things work in crystal too
<FromGitter>
<sam0x17> like I'm probably going to teach my nephew some basic C stuff and make him use malloc and such before he gets the privilege of garbage collection
<FromGitter>
<bew> or make him write some Crystal without the stdlib :P
<FromGitter>
<sam0x17> the good thing is the stdlib in crystal is very, very good compared to a lot of languages, and at this point the basic building blocks you need for pretty much anything
<FromGitter>
<sam0x17> yes actually that is a good idea
<FromGitter>
<drinkmorewaters> I believe lots of people are planning to do these or have done these, so i am very much looking forward to it!
<FromGitter>
<sam0x17> well if you ever get into the whole "serverless" movement I've written a shard that lets you deploy crystal to google cloud functions: https://github.com/sam0x17/gcf.cr the appeal is you can write crystal code for specific endpoints and pay 0.0000000001 cents per invocation instead of paying 10 cents an hour for a web server, and be able to handle enormous traffic spikes etc. So a serverless app is usually a
<FromGitter>
... huge javascript frontend that is stored in S3 / google cloud storage / wasabi / etc and all the end points are lambda / cloud functions, so you have no servers, just a bunch of virtually infinitely scalable things that are dirt cheap
<FromGitter>
<j8r> @sam0x17 still, don't begin too hard. I would say start as easy as possible (even Scratch lang) and then if the child likes we can go further 😁
<FromGitter>
<sam0x17> yeah, agreed
<FromGitter>
<drinkmorewaters> I looked at your shard and have looked at serverless which i'd love to be able to do at some point
<FromGitter>
<sam0x17> I might fall back on python + minecraft
<FromGitter>
<j8r> That's a good one!
flaviodesousa has joined #crystal-lang
<FromGitter>
<sam0x17> @drinkmorewaters thanks! that shard is also very straightforward to pick apart because I tend to code in a very deliberate obvious sort of way with very few includes so feel free to pick through it as an educational exercise it will probably be a lot easier to follow than other shards
<FromGitter>
<sam0x17> python is just ruby-like enough that it hurts not being ruby lol
<FromGitter>
<j8r> @drinkmorewaters for example, i recommend you to read the files in `spec` folders of projects like Crystal. You can also read the stdlib
<FromGitter>
<sam0x17> thats a super good idea
<FromGitter>
<sam0x17> specs show you how everything works
<FromGitter>
<j8r> @sam0x17 It wouldn't be more Lua for minecraft plugins?
<FromGitter>
<sam0x17> there's a python API
<FromGitter>
<sam0x17> but generally yes
<FromGitter>
<sam0x17> I've never had to take the Lua plunge myself so going to avoid that for now
<FromGitter>
<sroller> @delef Never apologise for your English :-)
<FromGitter>
<j8r> sorry for my French, you can :)
<FromGitter>
<delef> @sroller why? 😀
<FromGitter>
<sroller> @delef I'm a German living in Canada. I did this all the time. People told me what I just wrote. I live close to Toronto where about 50% of the people were not born in Canada! It is said that in the Greater Toronto Area (GTA) people speak 92 mother tongues. All the native english canadians speak one language. The rest is bilingual :-). Also, there are probably >1E+09 people in the world who speak English. Most
<FromGitter>
... of them as a second language. There is no reason to apologise.
<FromGitter>
<delef> @sroller I'm understood, thank you 🙂
Raimondi has joined #crystal-lang
renzhi has quit [Quit: WeeChat 2.1]
renzhi has joined #crystal-lang
akaiiro has joined #crystal-lang
duane has joined #crystal-lang
<FromGitter>
<fridgerator> Is it not possible to override methods which take a `&block` / `Proc` argument? https://carc.in/#/r/4mfx
<FromGitter>
<bew> @sam0x17 I recommend Minecraft with the mod Computercraft where you can program a lot of cool things in Lua
<FromGitter>
<delef> without recursive types you can't solve many problems :(
snsei has quit [Read error: No route to host]
<FromGitter>
<j8r> Yeah, personally not againt
<FromGitter>
<j8r> I underline that `#as(Type` is not good
<FromGitter>
<j8r> That's an unsafe hack,
<FromGitter>
<j8r> What do you want to achieve? You actual implementation seems to work
<FromGitter>
<j8r> Why you dont do `{ SomeType.as_s => SomeType.as_i}`?
<FromGitter>
<j8r> Or `SomeType.new("Name")` i guess
wontruefree has joined #crystal-lang
<FromGitter>
<sam0x17> @bew thanks ill check it out
<crystal-gh>
[crystal] kostya opened pull request #6458: Fix JSON::Serializable with 2 args, and YAML::Serializable with 3 arg… (master...fix_json_with_two_fields) https://git.io/fNzEN
<FromGitter>
<delef> The answer to the recursive types was sent to @asterite. ⏎ @j8r I wanted to get `{} of SomeType => SomeType` with content
<FromGitter>
<paulcsmith> I think it has something to do with `Array` being generic because if I change it to just accept a `Filter` and not `Array(Filter)` it works fine...hmm 🤔
kosmonaut has quit [Remote host closed the connection]
wontruefree has quit [Read error: Connection reset by peer]
snsei has joined #crystal-lang
<FromGitter>
<asterite> Ivan: yes you can, see JSON::Any in the standard library. It's recursive without using recursive aliases. Recursive aliases are a smell and they will eventually be removed from the language.
rohitpaulk has joined #crystal-lang
akaiiro has quit [Ping timeout: 244 seconds]
DTZUZO has quit [Ping timeout: 268 seconds]
rohitpaulk has quit [Read error: Connection reset by peer]
<oprypin>
also seems like a terrible example of interface
<FromGitter>
<Blacksmoke16> was talking about @kazzkiq example
<FromGitter>
<Blacksmoke16> that, that sort of setup doesnt exist in crystal, would have to be a class/struct for what he wants
<FromGitter>
<Blacksmoke16> or a hash/named tupled alias'd to the keyword `User` like his example
<oprypin>
i suppose
duane has quit [Ping timeout: 268 seconds]
wontruefree has quit [Quit: bye]
TCZ has joined #crystal-lang
wontruefree has joined #crystal-lang
DTZUZO has joined #crystal-lang
Philpax has joined #crystal-lang
TCZ has quit [Quit: Leaving]
wontruefree has quit [Quit: bye]
alex`` has joined #crystal-lang
duane has joined #crystal-lang
duane has quit [Ping timeout: 240 seconds]
<FromGitter>
<kazzkiq> Guys I tried to work on it using struct, classes and modules. Not sure what I'm doing wrong, but it didn't worked. If you could please provide a micro example with actual code, it would be much appreciated.
<FromGitter>
<kazzkiq> I also read the classes docs, but some things are easier to wrap your rlhead about when seeing actual code instead of text, I suppose.
<FromGitter>
<Blacksmoke16> `user : User` makes that method only take a instance of the `User` class
<FromGitter>
<Blacksmoke16> while `NamedTuple(name: String, age: Int32)` could take any named tuple that has those properties/data types
<FromGitter>
<Blacksmoke16> doesnt *have* to be a user
Philpax has quit [Ping timeout: 240 seconds]
<FromGitter>
<kazzkiq> Hmm, got it! My error was trying to pass the NamedTuple directly to the function (that only accepted my class).
<FromGitter>
<Blacksmoke16> mhm that would do it
<FromGitter>
<kazzkiq> I was thinking that by giving my parameter a type of a class (that returns a NamedTuple) it would simply serve as an alias to that tuple, so by typing it directly would work, too.
<FromGitter>
<Blacksmoke16> this would also work
<FromGitter>
<kazzkiq> Only because of the below function in your example, right?