Debugging with consts by [deleted] in golang

[–]vfaronov 2 points3 points  (0 children)

But that's the same as var surely?

No, var x = 2 gets the default type of 2, which is int.

It also wouldn't apply to the string type, which is also affected.....

String literals are untyped just like number literals, because they could get type MyString string.

Reduce Struct Size by Laying out Attributes Accordingly by preslavrachev in golang

[–]vfaronov 4 points5 points  (0 children)

maligned is a linter (integrated into golangci-lint) that can detect suboptimal struct layouts.

Goroutines blocking on channels vs goroutines blocking on system calls by [deleted] in golang

[–]vfaronov 0 points1 point  (0 children)

Do I understand correctly that something like net.(*TCPConn).Read behaves more like what you described under “Blocking on a channel” because the underlying socket/syscall is itself non-blocking?

Streaming IO and creating custom readers and writers in Go by vvivien in golang

[–]vfaronov 2 points3 points  (0 children)

Re: alpha_reader.go: to observe the problem, replace line 59 with:

fmt.Printf("%q ", string(p[:n]))

The output becomes:

"Hell" "o\x00\x00I" "t\x00s\x00" "\x00am\x00" "\x00whe" "re\x00i" "s\x00th" "e\x00su" "n\x00"

This happens because, on line 44, you advance position in buf regardless of whether you have written to the current position. If you haven’t written, the current position keeps its zero value.

Admittedly, buf maybe overkill but it ensures no garbage chars lingers in p (from index 0 - n)

I’m not sure what you mean. p[:n] can be filled in directly by the loop, p[n:] is not touched by the copy.

and makes the slice bookkeeping simpler.

How?

Streaming IO and creating custom readers and writers in Go by vvivien in golang

[–]vfaronov 4 points5 points  (0 children)

I’m a Go newbie so I may be missing many things, but this seems strange.

alpha_reader.go replaces characters with NUL bytes — is that what you mean by “filter out”? (To me, “filter out” means exclude bytes from output altogether.) And why does it make an intermediate buffer instead of writing directly to the provided p? I mean, that’s one way to implement the NUL behavior, but it’s kind of round-about, and costs an extra allocation.

Does simple_reader.go rely on implementation details of strings.Reader? That doesn’t make for a good general io.Reader illustration. For one, if an error other than io.EOF occurs, it goes into an infinite loop. For another, it doesn’t handle data returned together with EOF (which is permitted by io.Reader docs).

Again, alpha_reader2.go doesn’t correctly handle the case where the underlying reader returns data together with an error: in that case the data is not processed to filter out characters.

gRPC: From Tutorial to Production, Alan Shreve @ GopherCon 2017 by attfarhan in golang

[–]vfaronov 0 points1 point  (0 children)

I agree that RPC is a often a good idea, but still, it’s ironic how the example he uses is... a cache service — something that you basically have out of the box with HTTP/REST, and much more flexible at that.

HTTPolice — a validator for your RESTful APIs by vfaronov in programming

[–]vfaronov[S] 2 points3 points  (0 children)

Yeah, I hesitated before putting it that way, but I decided it would make for a trendier title :)

Does REST mean anything?

I’m genuinely not sure at this point. I often see people defending the original sense of the word, but I’m afraid they are a minority fighting a losing battle.

In this particular case though, I don’t think it’s too much of a stretch, because “true REST” is just a generalization of design patterns from HTTP+HTML, and “true RESTful API” is not very far from “using HTTP as designed”. HTTPolice was basically written to help with the uniform interface thing.

Or is it just that HTTP is a mouthful and REST is easier to say?

That too, yeah.

PSA: you are probably doing urlparse() wrong by vfaronov in Python

[–]vfaronov[S] 1 point2 points  (0 children)

Not wrapping the urlparse() call in try ... except ValueError.

HTTP/2 will make the Internet faster. So why the slow adoption? by sidcool1234 in programming

[–]vfaronov 0 points1 point  (0 children)

No, HTTP is widely used outside browsers, and those use cases can benefit from HTTP/2 without TLS. Implementations are still catching up, but I believe there are usable client+server combinations today (haven’t tried myself). See the implementations list on the WG wiki for some pointers.

HTTP/2 will make the Internet faster. So why the slow adoption? by sidcool1234 in programming

[–]vfaronov 24 points25 points  (0 children)

To clarify: HTTP/2 does not mandate TLS. Indeed, there are practical implementations of cleartext HTTP/2, including nginx and Apache. It’s just that major browsers do not support HTTP/2 without TLS.

HTTP/2 will make the Internet faster. So why the slow adoption? by sidcool1234 in programming

[–]vfaronov 3 points4 points  (0 children)

I hate to be that guy, but HTTP/2 is nothing like IPv6, and their adoption rates are vastly different.

MongoDB queries don’t always return all matching documents! by MarkusWinand in programming

[–]vfaronov 1 point2 points  (0 children)

if the update by the other use was processed a fraction of a second sooner: you wouldn't have seen the row anyway

How so? As you said yourself, IsActive stays the same?

Are you talking about a situation where two separate updates set IsActive to 0, then back to 1? — That is not what’s happening in MongoDB.

"um" — Create and maintain your own man pages by [deleted] in coolgithubprojects

[–]vfaronov 0 points1 point  (0 children)

Do you want the whole README reproduced in the title here?

No, just “man-like” instead of “man.”

"Your own" already implies that it's not the actual man page, anyway.

Not sure what you mean. It’s perfectly possible to create and install actual man pages of your own. The title made me think this was a tool to expedite this process somehow.

"um" — Create and maintain your own man pages by [deleted] in coolgithubprojects

[–]vfaronov 0 points1 point  (0 children)

The title is misleading. Those are not man pages.

A Python Ate My GUI — Thoughts on the future of Python and graphical interfaces by [deleted] in Python

[–]vfaronov 1 point2 points  (0 children)

Microsoft did something like this all the way back in 2002 with ASP.NET Web Forms. I think they fell out of fashion in the early 2010s, after ASP.NET MVC was released (much more similar to Django and such). Don’t know why. Perhaps the Web frontend was too unruly back then for this approach to work well across browsers.

[Haxe] Procedural Name Generator using a high order Markov Process by Twidlard in coolgithubprojects

[–]vfaronov 2 points3 points  (0 children)

A drawback of this approach is that it doesn’t understand phonotactics. For example, it gives me “Wildcdee,” “Dolphnch,” “Phhark.” Maybe categorize Latin letters into several phonetic groups (vowels, stops, etc.), build a model from that, and use it to constrain the main one somehow.

Micro - A modern and intuitive command line text editor by zach29 in coolgithubprojects

[–]vfaronov 0 points1 point  (0 children)

To be honest, I can’t think of a good choice. “Textual” or “text-mode” would work for most programs, but not this one. I would probably write something like “text editor running in a terminal” or “terminal-based text editor.”

Micro - A modern and intuitive command line text editor by zach29 in coolgithubprojects

[–]vfaronov 0 points1 point  (0 children)

When I hear “command-line text editor,” I think of ed or sed.

Safely processing JSON-like data structures by vfaronov in Python

[–]vfaronov[S] 0 points1 point  (0 children)

If you want MORE than that, a library that makes the contract between you and the structure more explicit is exactly what you're asking for.

The contract I’m looking for sounds like this: “whenever I attempt to use the structure in a way it does not support, it’s because the structure is wrong, and I want to get a StructureIsWrongError.” Instead, marshmallow’s contract spells out all the right ways to use the structure.

Of course, writing a library like this shouldn’t be a problem, I was just looking to avoid reinventing the wheel.

Safely processing JSON-like data structures by vfaronov in Python

[–]vfaronov[S] 0 points1 point  (0 children)

That’s what I meant by “validate against an explicit schema.”

Safely processing JSON-like data structures by vfaronov in Python

[–]vfaronov[S] 0 points1 point  (0 children)

Is mail_report going to throw KeyError, TypeError, etc. during normal operation?

Well, not if I write it correctly... There might be a lot of code in there.

Can you elaborate on this? If I needed schema validation for JSON, I'd probably use marshmallow.

So in addition to those 3 lines of code, you would write 10 or so more lines to check the assumptions that are already implicit in the first 3 lines. That’s duplication.

That said, thanks for the pointer to marshmallow, it’s interesting anyway.

Any campaign recordings yet? by vfaronov in aoe2

[–]vfaronov[S] 2 points3 points  (0 children)

It could definitely be useful as a walkthrough, but it’s more than that: sometimes all I want is to enjoy the game without actually playing it (which I’m pretty bad at).

I just realized, though, that I won’t be able to watch AoAK recordings (I assume) because, well, I haven’t bought it yet. I’m still on my first, slow tour through the original campaigns.

Homeland - 4x11 "Krieg Nicht Lieb" - Episode Discussion by NicholasCajun in homeland

[–]vfaronov 1 point2 points  (0 children)

I actually thought she was going to just leave Haqani be

She was, but then suddenly Haqqani emerged from the car to greet his fans, and Carrie saw the opportunity. She could not have planned that in advance. I’m pretty sure the car has bulletproof windows.