ChanServ changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.33.0 | Fund Crystal's development: http://is.gd/X7PRtI | GH: https://github.com/crystal-lang/crystal | Docs: http://crystal-lang.org/docs/ | API: http://crystal-lang.org/api/ | Gitter: https://gitter.im/crystal-lang/crystal
<FromGitter> <sam0x17> how do I make a custom class serializable to json, as in I just want it to be a flat string and ignore the fields on it
<FromGitter> <Blacksmoke16> prob can define a `to_json(builder : JSON::Builder)` on it
<FromGitter> <sam0x17> ty
ur5us has quit [Ping timeout: 240 seconds]
ur5us has joined #crystal-lang
<FromGitter> <stronny> any reason arrays don't have `def +(offset : Int)` ?
<FromGitter> <stronny> `ary[n..]` isn't particularily obvious syntax either
rohitpaulk has quit [Ping timeout: 250 seconds]
chachasmooth has quit [Ping timeout: 250 seconds]
chachasmooth has joined #crystal-lang
sz0 has quit []
sz0 has joined #crystal-lang
_ht has joined #crystal-lang
<FromGitter> <mnhattt> what ide/code editor work well with crystal at now ?
<FromGitter> <sam0x17> vscode
<FromGitter> <grkek> We need a better language server for the vs code editor
<FromGitter> <neutrinog> I'm writing a macro and checking to see if an instance variable `is_a?(...)` but it doesn't seem to be working.
<FromGitter> <grkek> Macro is compile time, that wont work probably?
<FromGitter> <neutrinog> I see it here in the macro documentation https://crystal-lang.org/api/0.33.0/Crystal/Macros/IsA.html
<FromGitter> <grkek> Can you provide me with your macro ?
<FromGitter> <neutrinog> there's a spec for it
<FromGitter> <grkek> interesting and what seems to be failing for you
<FromGitter> <grkek> are there any macro errors?
<FromGitter> <neutrinog> no the macro compiles correctly, but the output is wrong
<FromGitter> <neutrinog> the problem is that in this case is_a? is always returning false
<FromGitter> <grkek> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5e86e844c05284385ae9caae]
<FromGitter> <grkek> this is what it returns
<FromGitter> <neutrinog> I forgot to comment out some stuff. Here's the clean code https://github.com/neutrinog/macro_bug/blob/master/src/macro.cr#L28
<FromGitter> <grkek> if you add this right after the for cycle you get the values of the is_a check ⏎ ⏎ `````` [https://gitter.im/crystal-lang/crystal?at=5e86e8d44e14eb618b99f81b]
<FromGitter> <neutrinog> this is the expected output
<FromGitter> <grkek> which instead of outputting true outputs the actual class which included the Serializable module
<FromGitter> <neutrinog> is_a? always returns a boolean. I was manually printing the class in the first version of the code you saw.
ur5us has quit [Ping timeout: 252 seconds]
<FromGitter> <grkek> Put ```puts {{ ivar.is_a?(Serializable) }}``` after the line 14 where the loop starts and spec your app.
rohitpaulk has joined #crystal-lang
ur5us has joined #crystal-lang
<FromGitter> <neutrinog> that gives the same result. I did realize this works `puts @{{ivar}}.is_a?(Serializable)` however i want to store it in a macro variable.
rohitpaulk has quit [Ping timeout: 256 seconds]
rohitpaulk has joined #crystal-lang
<FromGitter> <xss2bruh> I want to suggest a universal comment that works in all programming languages
<FromGitter> <xss2bruh> please share this
<FromGitter> <neutrinog> @grkek I figured it out `Serializable.includers.any? { |t| t == ivar.type }`. thanks for taking a look at my code.
<FromGitter> <grkek> go ahead @xss2bruh
<FromGitter> <grkek> Oh damn @neutrinog I love macros but they hate me
Human_G33k has joined #crystal-lang
HumanGeek has quit [Ping timeout: 256 seconds]
<FromGitter> <j8r> universal comment? @xss2bruh
<FromGitter> <xss2bruh> yes
<FromGitter> <xss2bruh> for every programming language
<FromGitter> <xss2bruh> maybe it's more convenient for others
<FromGitter> <grkek> @xss2bruh stop being weird
<FromGitter> <grkek> and say it already
<FromGitter> <xss2bruh> oh
<FromGitter> <xss2bruh> sry for being weird
<FromGitter> <grkek> no you are not being weird I just joked around
<FromGitter> <grkek> send us your idea
<FromGitter> <xss2bruh> ok
<FromGitter> <xss2bruh> so
<FromGitter> <xss2bruh> should I start a chatroom somewhere
<FromGitter> <xss2bruh> on a chatting platform
<FromGitter> <j8r> is it just `# ` vs `//`
<FromGitter> <j8r> in-code comments?
<FromGitter> <j8r> @xss2bruh Sure, choose one in https://en.wikipedia.org/wiki/Online_chat#Software_and_protocols
<FromGitter> <xss2bruh> look
<FromGitter> <xss2bruh> @j8r thanks
<FromGitter> <xss2bruh> :)
<FromGitter> <xss2bruh> maybe this
<FromGitter> <j8r> We still don't know what is the proposal...
<FromGitter> <j8r> It is not even explained in the issue
<FromGitter> <xss2bruh> so
<FromGitter> <xss2bruh> I am trying to convince devs to make a universal comment that works in any language
<FromGitter> <xss2bruh> It may help ppl
<FromGitter> <j8r> code comments?
<FromGitter> <j8r> What do you mean by universal?
<FromGitter> <xss2bruh> yes
<FromGitter> <xss2bruh> universal = works in all programming language
<FromGitter> <xss2bruh> languages*
<FromGitter> <xss2bruh> yes, code comments
<FromGitter> <j8r> that's just the sign indicating the comment, like `#` or `//`?
<FromGitter> <j8r> what do we have to change?
<FromGitter> <xss2bruh> these signs don t act as comments in all programming languages
ur5us has quit [Ping timeout: 256 seconds]
<FromGitter> <xss2bruh> for example `#` is not a comment in markdown
<FromGitter> <xss2bruh> it makes titles(headers)
<FromGitter> <xss2bruh> they're `<h3>` tags
<FromGitter> <xss2bruh> so my idea
<FromGitter> <xss2bruh> is that we make a combination of simbols that work as a comment in every(a lot) programming language
<FromGitter> <xss2bruh> I provided a link, if someone want's to join
rohitpaulk has quit [Ping timeout: 256 seconds]
<FromGitter> <j8r> it won't be possible
<FromGitter> <j8r> for example `//` is floor division, `1 // 2` is an expression whereas in JS `2` is a comment
<FromGitter> <j8r> any combination of `#` and `//` won't work without changing the language
<FromGitter> <alex-lairan> Why `//` should be a comment? ⏎ I think that comment should be `#// My comment` thank this everyone will be disappointed. :D
<FromGitter> <j8r> `1 #// 2` in crystal, the comment is `// 2` ⏎ In JS, the comment is `2` - and I think `1 #` as an expression is not valid
<FromGitter> <xss2bruh> we will try something else
<FromGitter> <xss2bruh> #//# comment #//#
<FromGitter> <xss2bruh> oh no
<FromGitter> <xss2bruh> no what I want
<FromGitter> <xss2bruh> `//# comment #//`
<FromGitter> <xss2bruh> like
<FromGitter> <xss2bruh> something
<FromGitter> <xss2bruh> multiline should be like: ⏎ ` ⏎ //# ⏎ multiline comment ⏎ ... [https://gitter.im/crystal-lang/crystal?at=5e8702960649fc5f355ca1db]
<FromGitter> <xss2bruh> `//# ⏎ multiline comment ⏎ //#`
<FromGitter> <xss2bruh> no
<FromGitter> <j8r> This proposal is not realistic :/
<FromGitter> <j8r> You should have posted it on April 1st :P
<FromGitter> <j8r> @xss2bruh `//` is floor division in Crystal - and the won't be any change to allow multiple ways to comment https://github.com/crystal-lang/crystal/pull/1401
<FromGitter> <xss2bruh> thanks
rohitpaulk has joined #crystal-lang
<FromGitter> <stronny> I think creating special syntax that's gonna be compatible with "a lot" of existing langs is not impossible
<FromGitter> <stronny> What is impossible indeed is then implementing it in every single one implementation of every single one syntax
postmodern has quit [Quit: Leaving]
<FromGitter> <Blacksmoke16> @neutrinog I'm assuming you already know about https://crystal-lang.org/api/master/JSON/Serializable.html
deavmi has quit [Quit: https://quassel-irc.org - Chat comfortably. Anywhere.]
MasterdonX has joined #crystal-lang
deavmi has joined #crystal-lang
masterdonx2 has quit [Ping timeout: 256 seconds]
<FromGitter> <alehander92> @xss2bruh it's very hard to do something like this
<FromGitter> <alehander92> you probably know some languages use `;`, some other symbols etc
<FromGitter> <alehander92> i can see the usefulness, but many editors already have a shortcut for that
deavmi has quit [Ping timeout: 256 seconds]
deavmi has joined #crystal-lang
deavmi has quit [Client Quit]
deavmi has joined #crystal-lang
Human_G33k has quit [Ping timeout: 258 seconds]
<FromGitter> <neutrinog> @Blacksmoke16 yes. That got me most of the way. Then I was stuck until I figured out how to manually check types in macros. Everything thing is working now. In case anyone cares, I'm building a serializer that will be used to map crystal classes to uniforms in glsl programs (vertex and fragment shaders).
<FromGitter> <neutrinog> All that for a 3d rendering library I'm building.
<FromGitter> <Blacksmoke16> 👍
<FromGitter> <Blacksmoke16> do they use a specific format or something?
<FromGitter> <neutrinog> not really. But I'm trying to abstract everything so it's easy to support custom shaders. The flow of logic is sort of like this: A developer creates a new class such as "SpotLight" that registers the file path to a glsl program, and annotates instance variables that will be bound to the glsl program. A shader class then does all the heavy lifting to bind values to the glsl program.
<FromGitter> <neutrinog> In other words, this will abstract away all of the OpenGL language. So adding a new shader with fancy lighting effects just requires a new crystal class.
<FromGitter> <Blacksmoke16> gotcha
<FromGitter> <xss2bruh> maybe I will try to make a package that will do the thing
<FromGitter> <Blacksmoke16> what thing?
<FromGitter> <xss2bruh> oh
<FromGitter> <xss2bruh> sry
<FromGitter> <xss2bruh> a universal type of comment that works in every programming language
<FromGitter> <Blacksmoke16> generally, or for documentation?
<FromGitter> <xss2bruh> it may be useful fo ppls
<FromGitter> <xss2bruh> what do you mean?
<FromGitter> <xss2bruh> sry
<FromGitter> <Blacksmoke16> like just for adding comments in your code, or like special comments used to document it like https://jsdoc.app/tags-returns.html
_ht has quit [Remote host closed the connection]
_ht has joined #crystal-lang
deavmi has quit [Quit: Going into the wilderness...]
deavmi has joined #crystal-lang
<FromGitter> <ImAHopelessDev_gitlab> hi
_ht has quit [Remote host closed the connection]
_ht has joined #crystal-lang
<FromGitter> <kinxer> Hey, @ImAHopelessDev_gitlab
<FromGitter> <manveru> @xss2bruh just take a quick look at https://rosettacode.org/wiki/Comments -- good luck :)
DTZUZU2 has joined #crystal-lang
HumanG33k has joined #crystal-lang
DTZUZU has quit [Ping timeout: 256 seconds]
HumanG33k has quit [Remote host closed the connection]
HumanG33k has joined #crystal-lang
DTZUZU has joined #crystal-lang
DTZUZU2 has quit [Ping timeout: 256 seconds]
<FromGitter> <lbarasti> I've been bitten by this behaviour ⏎ ⏎ ```code paste, see link``` ⏎ ⏎ I'd have expected `typeof(x)` to be `B | C`? [https://gitter.im/crystal-lang/crystal?at=5e8780d913756133c89a783b]
<FromGitter> <Blacksmoke16> its because `A` isnt abstract
<FromGitter> <Blacksmoke16> type goes to the parent most type
<FromGitter> <Blacksmoke16> because in this `B` and `C` are essentially the same thing as `A`
<FromGitter> <lbarasti> unfortunately, that does not seem to make a difference ⏎ https://play.crystal-lang.org/#/r/8tns
<FromGitter> <Blacksmoke16> same idea tho
<FromGitter> <xss2bruh> @manveru thanks
<FromGitter> <xss2bruh> will do my best
<FromGitter> <xss2bruh> :)
<FromGitter> <Blacksmoke16> sounds like a noble goal, but without much benefit 😉
<FromGitter> <xss2bruh> yes
<FromGitter> <lbarasti> @Blacksmoke16 I'll see what happens with modules...
<FromGitter> <xss2bruh> I will try to do a package that will do that
<FromGitter> <xss2bruh> I will make it for atom
<FromGitter> <lbarasti> that's better! https://play.crystal-lang.org/#/r/8tnv
rohitpaulk has quit [Ping timeout: 265 seconds]
DTZUZU2 has joined #crystal-lang
DTZUZU has quit [Ping timeout: 264 seconds]
<FromGitter> <manveru> is there any way to make `crystal tool format` more opinionated about line lengths and not preserving newlines at all cost?
<FromGitter> <Blacksmoke16> i.e. set a limit on line length?
<FromGitter> <manveru> yeah
<FromGitter> <Blacksmoke16> the point of the format tool is to provide a common format all projects can use. if customization is allowed then it defats the purpose
<FromGitter> <Blacksmoke16> ameba supports that iirc tho
<FromGitter> <manveru> well, if it would completely discard the existing formatting, i'd agree, but it obviously doesn't :)
<FromGitter> <manveru> so i still have to manually adjust stuff... i just want a unified format, not options really
<FromGitter> <manveru> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5e87842bceabcb659d43dd49]
<FromGitter> <manveru> those are all equally valid formattings atm
<FromGitter> <Blacksmoke16> id argue some of those are probably bugs
<FromGitter> <Blacksmoke16> or at least something that could be added
<FromGitter> <manveru> i didn't know ameba could do code formatting... will check it
<FromGitter> <Blacksmoke16> well sorry, to be clear it doesnt change anything, but would inform you
<FromGitter> <manveru> ah, damn :|
<FromGitter> <Blacksmoke16> i.e. if a line is over x
<FromGitter> <manveru> yeah, not that useful then, i just want everything to be consistent no matter how i write it :)
<FromGitter> <Blacksmoke16> could maybe open an issue about formatting of method arguments
<FromGitter> <manveru> more like prettier/mint/elm does it
<FromGitter> <Blacksmoke16> id expect for arguments to be either in the same line or like your #2 example
<FromGitter> <manveru> well, it's the same issue for hashes and tuples and arrays
<FromGitter> <Blacksmoke16> same concept really
<FromGitter> <manveru> and i didn't want to start another religious war about how they should look like :)
<FromGitter> <Blacksmoke16> i dont like how it doesnt add a trailing comma 😉
<FromGitter> <Blacksmoke16> in method argument list iirc
<FromGitter> <manveru> this is also valid: ⏎ ⏎ ```foo(bar: baz ⏎ , foobar: foobaz ⏎ )``` [https://gitter.im/crystal-lang/crystal?at=5e8786db3a802a49d875ee24]
<FromGitter> <manveru> :)
<FromGitter> <manveru> i'd actually like that too... guess i've been damaged by FP a bit
<FromGitter> <Blacksmoke16> oh boy
<FromGitter> <manveru> i thought about fixing it myself, but the formatter code is 5k LoC
<FromGitter> <manveru> easiest might be to enforce a max line length and discard any existing newlines within expressions
<FromGitter> <manveru> but that still touches almost all of the code i fear
<FromGitter> <Blacksmoke16> :shrug:
<FromGitter> <manveru> anw, will make an issue and hope someone smarter than me can make it happen
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 260 seconds]
<FromGitter> <manveru> there you go
<FromGitter> <Blacksmoke16> 👍 9001, so close :p
<FromGitter> <Blacksmoke16> *its over 9000*
_ht has quit [Remote host closed the connection]
_ht has joined #crystal-lang
DTZUZU2 has quit [Ping timeout: 260 seconds]
DTZUZU has joined #crystal-lang
postmodern has joined #crystal-lang
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 265 seconds]
zorp has quit [Quit: {#`%${%&`+'${`%&NO CARRIER]
<FromGitter> <robacarp> s
_ht has quit [Remote host closed the connection]
_ht has joined #crystal-lang
zorp has joined #crystal-lang
_ht has quit [Quit: _ht]
<FromGitter> <manveru> guess i'll have to wait until someone writes this is a new tool then
deavmi has quit [Ping timeout: 265 seconds]
<FromGitter> <kinxer> @manveru I'll admit, I don't *love* the phrasing "a formatter that reduces creative freedom to a minimum". :P
<FromGitter> <manveru> but it's exactly what I want, I really love this part about Mint, Elm, and JS, never spend a second thinking about formatting :)
<FromGitter> <manveru> and while crystal is better about it than ruby+rubocop already, it's still neither making everyones code look consistent, nor configurable enough to allow for it
<FromGitter> <kinxer> Yeah, I believe that it's what you want, and I think I understand the reasoning for it. I just want to be a *person* when I'm coding, not only a productive agent.
<FromGitter> <kinxer> I know that's not an optimally efficient way to work on software, though, especially in an organization.
<FromGitter> <manveru> yeah, I've introduced Crystal to people in my team, and they write stuff with it, but it's just a lot of work to clean up after them :)
<FromGitter> <kinxer> That's fair. The few people in my office who use Crystal have a style guide we use, but having an automatic tool (to supplement `crystal format` or perhaps some way to configure it) would be nice.
<FromGitter> <Blacksmoke16> ameba can help identify some stuff, but fixing it would have to be manual atm
<FromGitter> <kinxer> I guess I understand the desire to have formatting be consistent over the entire language, but actual people (and therefore organizations) differ as to what specifics they believe make code more maintainable.
<FromGitter> <kinxer> For example, the small group of Crystal programmers I work with decided that ⏎ ⏎ ```code paste, see link``` ⏎ ⏎ makes sense for method calls with long arguments or long argument names. [https://gitter.im/crystal-lang/crystal?at=5e87aa8d50a27d11c7e91731]
<FromGitter> <Blacksmoke16> i tend to agree
<FromGitter> <kinxer> But not everyone needs to agree about that.
<FromGitter> <kinxer> I personally tend to use lots of vertical whitespace in my code to separate "logical sections" (arguably, refactoring to methods would be better in some cases...), but not everyone works that way.
<FromGitter> <stronny> I think Ruby is built in such a way that makes a unviersal style guide impossible
<FromGitter> <stronny> And Crystal by extension
<FromGitter> <stronny> creativity, productivity, freedom > predictability, replaceability, boredom imo
<FromGitter> <manveru> i guess after 15 years of ruby, i just don't think of code formatting as creative anymore... it's just a chore at this point :P
<FromGitter> <stronny> do you have a separate fomatting stage?
<FromGitter> <manveru> stage?
<FromGitter> <stronny> I don't look at this as some distinct entity called "formatting"
deavmi has joined #crystal-lang
<FromGitter> <manveru> ah, yeah
<FromGitter> <stronny> the way code looks is the result of author's thought and expression
<FromGitter> <stronny> anyway, I often dislike other people's code, and by the same token do not require from others any favors from mine
<FromGitter> <stronny> you do you, I'm gonna do me, win-win
<FromGitter> <manveru> i really don't think much about formatting while writing code, it formats on save, but in crystal i have to go through everything i wrote and make it look consistent again.
<FromGitter> <manveru> just the fact that we're talking about this is already a waste of time really... didn't want to drag it out that much, sorry
<FromGitter> <stronny> well I care a lot about how my code looks. I'm that guy that idents with tabs and strips trailing spaces and aligns everthting just right
<FromGitter> <stronny> I don't mind some talk really, but okay
<FromGitter> <kinxer> "Indents with tabs" D:
<FromGitter> <kinxer> :P
rohitpaulk has joined #crystal-lang
<FromGitter> <kinxer> That is a nice example, though. It works for some people and not for others.
<FromGitter> <stronny> yep
rohitpaulk has quit [Ping timeout: 265 seconds]
ur5us has joined #crystal-lang
<FromGitter> <robacarp> man I wish more people used tabs
<FromGitter> <robacarp> only because I can't stand to look at code that's indented with 4 spaces
ur5us has quit [Quit: Leaving]
darkstarx has joined #crystal-lang
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 240 seconds]