this post was submitted on 09 Jun 2024
230 points (79.9% liked)

> Greentext

7522 readers
1 users here now

founded 3 years ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[–] Pencilnoob@lemmy.world 13 points 1 year ago (6 children)

aspnet core is the library you want

Simple and just works

[–] mozz@mbin.grits.dev 4 points 1 year ago (5 children)

Simple and just works

    def fetch_html(self, url):
        domain = urllib.parse.urlparse(url).netloc
        if domain not in self.robot_parsers:
            rp = urllib.robotparser.RobotFileParser()
            rp.set_url(f'https://{domain}/robots.txt')
            rp.read()
            self.robot_parsers[domain] = rp

        rp = self.robot_parsers[domain]
        if not rp.can_fetch(self.user_agent, url):
            print(f"Fetching not allowed by robots.txt: {url}")
            return None

        if self.last_fetch_time:
            time_since_last_fetch = time.time() - self.last_fetch_time
            if time_since_last_fetch < self.delay:
                time.sleep(self.delay - time_since_last_fetch)

        headers = {'User-Agent': self.user_agent}
        response = requests.get(url, headers=headers)
        self.last_fetch_time = time.time()

        if response.status_code == 200:
            return response.text
        else:
            print(f"Failed to fetch {url}: {response.status_code}")
            return None

Randomly selected something from a project I'm working on that's simple and just works. Show me less than 300 lines of .NET to do the same, and I would be somewhat surprised.

[–] Pencilnoob@lemmy.world 2 points 1 year ago (2 children)

Well with your mild surprise on the line the stakes couldn't be higher

I know C# works, it pays my bills so that's good enough for me.

Here's a good place to see what it can do:

https://learn.microsoft.com/en-us/aspnet/core/tutorials/first-web-api?view=aspnetcore-8.0&tabs=visual-studio

[–] mozz@mbin.grits.dev 0 points 1 year ago (1 children)

I am familiar.

Not saying don't pay your bills with it; that part sounds great. I was just confused by this guy's enthusiasm for it, that's all.

[–] AdamBomb@lemmy.sdf.org 1 points 1 year ago

Well, for starters, it's a greentext, so who knows how genuine it is, right? Most of the points listed are either subjective or citation needed fodder. However, maybe there's one fact I can bring to the table:

ASP.NET's benchmark performance ranked 16th in Round 22 of the TechEmpower Web Framework Benchmarks, ranking below solutions written in Rust, C, Java, and JS. C# has advantages over each of those languages and frameworks in exchange for the relative loss in performance. Rust and C are much lower level. Java's syntax is generally considered to lag behind C#'s at this point. JS's disadvantages could fill a whole post of their own. C# and .NET have their own disadvantages (such as relatively fewer libraries available) as you've pointed out in this thread and another in this post, but when you take into consideration the relatively high performance while being a strongly-typed higher-level language with plenty of nice QoL features, you might be able to see why it could be attractive to a specific slice of professionals.

load more comments (2 replies)
load more comments (2 replies)