• Activity
  • Votes
  • Comments
  • New
  • All activity
    1. What programming/technical projects have you been working on?

      This is a recurring post to discuss programming or other technical projects that we've been working on. Tell us about one of your recent projects, either at work or personal projects. What's...

      This is a recurring post to discuss programming or other technical projects that we've been working on. Tell us about one of your recent projects, either at work or personal projects. What's interesting about it? Are you having trouble with anything?

      9 votes
    2. What TLDs do you view the most positively?

      I'm thinking of registering a new domain to host a personal blog and a few other pages that is somewhat separate from my current personal portfolio page, as the blog will likely not be directly...

      I'm thinking of registering a new domain to host a personal blog and a few other pages that is somewhat separate from my current personal portfolio page, as the blog will likely not be directly relevant to my work. But since this is a more personal project, I want to branch out in terms of TLDs - I've previously used exclusively .com endings as they lead to the least confusion and are the most accepted.

      I'm a little overwhelmed by the number of options these days, so I wanted to take a little straw poll to see which ones people think are the best. The name itself will be my initials "gpxl", and the endings I am considering are

      • .info
      • .xyz
      • .fyi
      • .computer
      • .me

      But I'm curious to see what others think. I would go with .xyz but I feel like then my domain name becomes an unintelligble string of letters - gpxl.xyz, so I'm wondering what others think and what arguments exist for choosing one over another.

      P.S. If anyone has recommendations for registars I'm open to those too. Currently using google domains but open to switching.

      18 votes
    3. What programming/technical projects have you been working on?

      This is a recurring post to discuss programming or other technical projects that we've been working on. Tell us about one of your recent projects, either at work or personal projects. What's...

      This is a recurring post to discuss programming or other technical projects that we've been working on. Tell us about one of your recent projects, either at work or personal projects. What's interesting about it? Are you having trouble with anything?

      14 votes
    4. A brief look at programming paradigms

      Overview If you've spent any significant amount of time programming, then you've probably heard discussions about imperative, functional, and declarative programming. These discussions are often...

      Overview

      If you've spent any significant amount of time programming, then you've probably heard discussions about imperative, functional, and declarative programming. These discussions are often mired in technical knowledge and require a fair amount of intuition when trying to grasp the differences between the examples placed in front of us. These different programming styles, usually called programming "paradigms", are discussed as if they exist within a vacuum with complete and total isolation from one another. This only furthers the confusion and frustration among newer programmers especially, which runs counter to the goal of instructing them.

      In this post I'll be taking a look at the oft-neglected intersections where these paradigms meet with the hope that the differences between them will be better understood by reframing our existing knowledge of programming basics.

      Note: I'll be using PHP for my code examples and will try to provide comments when necessary to point out language quirks.


      Understanding Fundamentals is Imperative

      Let's start by first reviewing the most basic, fundamental programming paradigm: imperative programming. The term is a bit strange, but the important thing to understand about it is that imperative programming refers to writing software as a series of instructions where you tell the computer how to solve a specific task. For example, if we need to add together a bunch of numbers inside of an array, we might write code that looks like this:

      $numbers = [ 8, 31, 5, 4, 20, 78, 52, 18, 96, 27 ];
      $sum = 0;
      foreach($numbers as $number) {
          $sum += $number;
      }
      

      This is a pretty typical example that you've probably encountered in some form or another at some point in your programming studies or career--iterate over an array one element at a time from the first element to the last and add the current element to some accumulating variable that starts at 0. The kind of loop you use may differ, but the general format of the solution looks the same. This is very similar to the way the computer itself performs the task, so the code here is just a relatively human-friendly version of the actual steps the computer performs. This is the essence of imperative programming, the basic building blocks of everything you learn early on.


      Abstract Concepts

      As the software we write gets larger and more complex, we then tend to rely on "abstractions" to simplify our code and make it easier to understand, reuse, and maintain. For example, if we've written a program that adds arrays of numbers together, then we probably aren't doing that in only one place. Maybe we've written a tool that generates reports on large data sets, such as calculating the total number of sales for a particular quarter, gross profit, net profit, remaining inventory, and any number of other important business-related metrics. Summing numbers could be so common that you use it in 30 different places, so to avoid having to maintain 30 separate instances of our number adding code from above, we define a function:

      function sum($numbers) {
          $sum = 0;
          foreach($numbers as $number) {
              $sum += $number;
          }
      
          return $sum;
      }
      

      We do this so frequently in our code that it becomes second nature. We attach so many names and terms to it, too: DRY, abstraction layers, code reuse, separation of concerns, etc. But one thing experienced programmers learn is to write their functions and object and interface methods in such a way that anyone who uses them doesn't need to care about the underlying implementation details, and instead only need to worry about the method name, expected arguments (if any), expected return type (if any), and expected behavior. In other words, they don't need to understand how the function or method completes the intended action, they only need to declare what action they want performed.


      A Declaration of Understanding

      Anyone who has looked into the concept of the declarative programming paradigm should find those last words familiar: "they don't need to understand how the function or method completes the intended action, they only need to declare what action they want performed". This is the oft-touted explanation of what declarative programming is, the difference between detailing "how" and declaring "what", and I believe that it's this great similarity that causes imperative and declarative programming to become heavily entwined in a programmer's mind and makes it difficult to understand. Take this common example that authors tend to use to try to detail the difference between declarative and imperative programming:

      // imperative
      function sum($numbers) {
          $sum = 0;
          foreach($numbers as $number) {
              $sum += 0;
          }
      
          return $sum;
      }
      
      // declarative
      function sum($numbers) {
          return array_reduce($numbers, fn($x, $y) => $x + $y, 0);
      }
      

      The authors will go on to state that in the imperative example, you tell the computer how to sum the numbers, whereas in the declarative example you don't tell the computer how to do it since you don't know anything about the reduce implementation, but intuitively it still feels as if you're telling the computer how to perform its task--you're still defining a function and deciding what its underlying implementation details are, i.e. the steps it needs to take to perform the task, even if its details are abstracted away behind function or method calls that could have varying implementation details of their own. So how the hell is this any different from defining functions like we do in imperative programming?

      The answer is simple: it isn't. We've used so many names and terms to describe functions and methods in our ordinary imperative programming, but the truth is that a well-defined function or method serves as a declarative interface to an imperative implementation. Put differently, declarative programming is defining and utilizing simple interfaces that describe what you want accomplished while the underlying implementation details are inevitably written using imperative code.


      Functional Differences

      Now we can finally tackle one of the biggest trends in programming right now: the functional programming paradigm. But to understand this paradigm, it's important to understand what a "function" is... from a mathematical perspective.

      Yes, I know, math tends to be a enthusiasm sink for many, but don't worry, we're not actually going to be doing math. We only need to understand how math treats functions. Specifically, math functions usually look something like f(x) = {insert expression here}, which is loosely equivalent to the following code:

      function f($x) {
          return {insert expression here};
      }
      

      The important thing to note about functions in math is that you can run them a theoretically infinite number of times on the same input x and still get the same return result. Unlike in a lot of the programs we can write, math functions don't produce side effects. Files aren't written to or destroyed, database entries aren't deleted, some global counter somewhere isn't incremented, and your x doesn't suddenly change. The idea behind functional programming is to embody some of that nature of mathematical functions because they're predictable and always reproducible, and therefore simple to test as well. For example, take the following:

      // not functional
      function increment(&$x) { // pass by reference--$x will be modified outside of this function!
          $x++;
      }
      
      $x = 1;
      increment($x);
      increment($x);
      increment($x);
      
      // functional
      function increment($x) { // pass by value--$x will NOT be modified outside of this function!
          return $x + 1;
      }
      
      $x = 1;
      $y = increment($x);
      $y = increment($x);
      $y = increment($x);
      

      Note that the first example will change the value of $x on each call, meaning each subsequent call of increment($x) produces a different result. Meanwhile the second example doesn't change $x and so the return value of increment($x) is always the same. This may seem like a silly example, but in larger, more complex software this can be significant. So now that we have an understanding of functions from a mathematical perspective, we have everything we need to actually understand what functional programming is.

      Functional programming is a subset of declarative programming. Just like in declarative programming, you use simple interfaces to tell the program what you want to do rather than how to do it. But unlike declarative programming as a whole, functional programming imposes some additional restrictions on what you should and shouldn't do:

      • You should encapsulate behavior in pure functions, which always give a consistent output for a given input and don't have side effects.

      • You should write functions in such a way that you can compose them together, allowing you to combine and chain behavior to produce new functions or use the output of one as the input for another.

      • You should avoid side effects as much as possible.

      • You should avoid mutable state (e.g. changing the values in a variable).

      • You should avoid sharing state between components.

      These restrictions would require an entirely separate post on their own to properly cover and have been covered so many times in so many ways by others elsewhere that it would be superfluous for me to try to add anything more. It's important to note, however, that these restrictions are imposed because they provide some key benefits. By avoiding side effects and by avoiding mutable and shared states, the code you write becomes more predictable and tracing the behavior of an algorithm becomes far simpler. By writing pure, composable functions, you create reusable building blocks that can be strung together in virtually any configuration with predictable results. This makes writing, reading, maintaining, and debugging code easier and less error-prone.

      That said, I feel that it's important to note that in the real world when writing practical software that users can interact with, it's simply not possible to completely avoid side effects or mutable state. The very act of creating and updating database entries is itself an act of mutating state, which runs contrary to functional programming principles and is essential for many important software projects. But even if you can't adhere strictly to functional programming principles, it's possible to benefit significantly from being aware of them and integrating them into your own software development strategies.

      Let's consider a more practical example to illustrate this. Imagine that you've built a social media website and you're trying to test a push notification system that will be triggered when your user receives a new message. Now imagine your code and unit tests look something like this:

      function sendNotification(&$message) { // pass by reference--$message will be modified outside of this function!
          $notification_system = new NotificationSystem();
          if(!$message['sent_push_notification']) {
              $notification_system->sendPushNotification($message);
              $message['sent_push_notification'] = true;
          }
      }
      
      function testSendNotification() {
          $message = [
              'user_id'=>'{some_id}',
              'contents'=>'Hi!',
              'sent_push_notification'=>false
          ];
      
          sendNotification($message);
          sendNotification($message);
      }
      

      At a quick glance you probably wouldn't be aware of why the second message didn't send, but the fact that our sendNotification() function mutates the state of the data provided to it is the culprit. This is code that doesn't adhere to functional programming principles since the data provided to it is mutated. As a result, running the function multiple times on the same variable doesn't result in the same behavior as the first call. If we wanted to work around this without adhering to functional programming principles then we would need to manually set $message['sent_push_notification'] = false; between function calls, which makes our unit tests potentially more error-prone. Alternatively we can make a simple change to adhere better to those functional principles:

      function sendNotification($message) { // pass by value--$message will NOT be modified outside of this function!
          $notification_system = new NotificationSystem();
          if(!$message['sent_push_notification']) {
              $notification_system->sendPushNotification($message);
              $message['sent_push_notification'] = true;
          }
      
          return $message;
      }
      
      function testSendNotification() {
          $message = [
              'user_id'=>'{some_id}',
              'contents'=>'Hi!',
              'sent_push_notification'=>false
          ];
      
          sendNotification($message);
          sendNotification($message);
      }
      

      Now both notifications will be sent out, which is what we would intuitively expect. You should also notice that the above is also a blend of imperative, declarative, and functional programming. Our function definitions have imperative code, our sendNotification() function adheres to the functional programming principle of avoiding mutable state (well, mostly), and our NotificationSystem object provides a declarative interface for sending a push notification for a message.


      Final Thoughts

      By viewing these three paradigms not as completely separate concepts but as layers on top of one another, where functional programming is a type of declarative programming which is implemented using imperative programming, we can stop being confused by their similarities and instead find clarification in them. By understanding that imperative programming is the backbone of everything, that declarative programming is just simplifying that backbone with simple interfaces, and that functional programming is simply adding some additional guidelines and restrictions to the way you write code to make it more consistent, reusable, and predictable, we can start to see that we're not choosing one programming paradigm over another, but instead choosing how much consideration we place on the design of the programs we write. Except in purely functional languages, functional programming isn't some alien concept distinct from imperative or declarative programming, but is instead a natural evolution of the two.

      There are a lot of details I've glossed over here. Each of these programming paradigms is far too detailed to include a proper analysis in an already lengthy post that tries to separate them from each other and clarify their differences. Blog articles exist in a thousand different places that can do each one far more justice than I can, and programming languages exist that completely cut imperative programming out of the picture. But for your average programmer slinging JavaScript, C, Rust, PHP, or what have you, I hope that this serves as a crucial starting pointing to understanding just what in the hell these functional programming enthusiasts are on about.

      25 votes
    5. What do you think of LeetCode? Did anyone of you succeed thanks to it?

      I've come across this website recently, and I'm genuinely wondering if it's really that useful for passing interviews. For example, I think it can not replace a solid background in algorithms/data...

      I've come across this website recently, and I'm genuinely wondering if it's really that useful for passing interviews.

      For example, I think it can not replace a solid background in algorithms/data structures and maybe CS courses in general.

      7 votes
    6. Fortnightly Programming Q&A Thread

      General Programming Q&A thread! Ask any questions about programming, answer the questions of other users, or post suggestions for future threads. Don't forget to format your code using the triple...

      General Programming Q&A thread! Ask any questions about programming, answer the questions of other users, or post suggestions for future threads.

      Don't forget to format your code using the triple backticks or tildes:

      Here is my schema:
      
      ```sql
      CREATE TABLE article_to_warehouse (
        article_id   INTEGER
      , warehouse_id INTEGER
      )
      ;
      ```
      
      How do I add a `UNIQUE` constraint?
      
      8 votes
    7. Would any Tilderino be interested in tutoring me in programming?

      I could have post this on Reddit but in my experience, nothing really happens over there since things are too impersonal. I realize that's not an enticing proposition for most people since...

      I could have post this on Reddit but in my experience, nothing really happens over there since things are too impersonal.

      I realize that's not an enticing proposition for most people since programmers are usually busy people, but I figure I'd give it a shot. I believe many people that already interacted with me have some idea about my personality. Besides being a stickler for logic, I'm very flexible and eager to learn and make it a habit to force myself to admit when I am wrong. I had to abandon software engineering college because of financial concerns and this hurt me quite a bit, not just because of the content, but because of the social stimulus from my peers.

      I already have some knowledge mostly in Python and basic C algorithms, from the basics until rudiments OOP. Math is not my strong suit, but I don't hate it either and I am very fond of logic (including philosophy). I'm also very good at Googling and reading documentation, so I wouldn't give you too much trouble.

      I'm proficient in Linux/Unix (as an advanced user, not an administrator). I'm comfortable in the command line and an enthusiastic user of Emacs (but I can use whatever you want of course).

      It doesn't even have to be Python, just anything you're comfortable teaching at a beginner level that works on a Mac (and later n a Linux Machine). And is also wouldn't have to be super intensive or frequent, being unemployed (hahaha) I can work around any schedule. I just need some human contact with a nice dude or dudette that cares about imparting knowledge.

      My English is pretty good in writing and understanding but I do have a thick accent -- I believe it's understandable though.

      I'm super shy and video is not a requirement, but it might be nice.

      I'm also a slow learner and have ADHD, so you might need a little patience.

      Anyway, here I am asking for help!

      EDIT: dear Tilderinos, you're awesome and I love you all. I'm also aware of many if not most learning resources for self-didact beginners programmers on the internet -- especially if they use Python. The reason I'm posting this is that I am failing at learning by myself. I welcome ALL suggestions with great gratitude, but this is not the purpose of this thread.

      EDIT2 VERY IMPORTANT!!! I’d be willing to teach Portuguese or anything else I happen to know in exchanging for the tutoring!!!!!!!

      EDIT3:

      Thank you very much everyone. I'm very sorry tor taking so long to answer. I had to make a decision about my study plans for 2020.

      Thing is, back in 2019 I was doing pretty well on a software engineering course at a local private university. But money got tight and I had to drop out. Since then I've been trying to make it on my own, but after more than a year I came to the conclusion that this is simply not going to work. At the university, I was at the top of the class. By myself, I'm a lazy bastard with half the IQ. Go figure.

      So I decided that instead of trying force my way into learning by myself, I'll just study for the Brazilian national exam and get into some great public educational facility that will most certainly provide me a better education for free.

      I took the exam before without studying, and my grade made the cut. So I'm confident that if apply myself this time I'll be able to enter at least one of three major public universities in my city that offer dozens of IT-related courses.

      So I'm laying off from programming until at least January 17 and devoting myself entirely to the exam.

      Cheers!

      18 votes
    8. What programming/technical projects have you been working on?

      This is a recurring post to discuss programming or other technical projects that we've been working on. Tell us about one of your recent projects, either at work or personal projects. What's...

      This is a recurring post to discuss programming or other technical projects that we've been working on. Tell us about one of your recent projects, either at work or personal projects. What's interesting about it? Are you having trouble with anything?

      11 votes
    9. I started a React and React Native screencast, I'd love to get your opinion on it

      I have always believed that sharing what you know is very important. Altruistically, it helps create a wealth of knowledge that anyone can build upon. Selfishly, it creates a knowledge-base for...

      I have always believed that sharing what you know is very important.

      Altruistically, it helps create a wealth of knowledge that anyone can build upon.

      Selfishly, it creates a knowledge-base for your future self, and - arguably more importantly - helps you build a following.

      After years of pondering on the idea, I took the plunge and started a screencast on React and React Native. I only published four episodes so far, and they are all very basic, but I'm planning on publishing a video every other day for a few months at least.

      It's called RNcasts. You can see it here. I would love to get your opinion on it.

      It's by no means perfect, it hurts my eyes to look at it, and it hurts my ears to hear my own voice, but I had to get started somewhere.

      Also, I will be sharing my journey of working on this screencast on the RNcasts blog. If you are interested in starting your own screencast or video course, feel free to follow it. I'm hoping to share all I learn, the good and the bad.

      4 votes
    10. What programming/technical projects have you been working on?

      This is a recurring post to discuss programming or other technical projects that we've been working on. Tell us about one of your recent projects, either at work or personal projects. What's...

      This is a recurring post to discuss programming or other technical projects that we've been working on. Tell us about one of your recent projects, either at work or personal projects. What's interesting about it? Are you having trouble with anything?

      18 votes
    11. Fortnightly Programming Q&A Thread

      General Programming Q&A thread! Ask any questions about programming, answer the questions of other users, or post suggestions for future threads. Don't forget to format your code using the triple...

      General Programming Q&A thread! Ask any questions about programming, answer the questions of other users, or post suggestions for future threads.

      Don't forget to format your code using the triple backticks or tildes:

      Here is my schema:
      
      ```sql
      CREATE TABLE article_to_warehouse (
        article_id   INTEGER
      , warehouse_id INTEGER
      )
      ;
      ```
      
      How do I add a `UNIQUE` constraint?
      
      5 votes
    12. How to design a database?

      I'm working on an application that allows a user to view playlists belonging to a particular radio show and stream/download/favourite the tracks in them. It has 4 core entities: User, Show,...

      I'm working on an application that allows a user to view playlists belonging to a particular radio show and stream/download/favourite the tracks in them. It has 4 core entities: User, Show, Playlist and Track.

      • Each show has multiple playlists (one-to-many)
      • Each playlist has multiple tracks (one-to-many)

      To be able to reference a playlist belonging to a particular show. I gave those playlists the same uuid as the show they belong to. A few questions though.

      1. Is this the right/best way to associate data?
      2. As a track could potentially belong to multiple playlists, I can't take the same approach as I do for (show/playlist) How would be best to handle this? Ideally I would like to have a single "Track" table containing all tracks for all playlists.

      For any experienced database designers out there, how would you structure this data? What would you consider in designing the schema and why? If I did go with 4 tables only, presumably there would be performance implications given the potential amount of data in any one of those tables, particularly tracks. If that is the case, how best to structure this kind of thing with performance in mind? Thanks in advance for any help :)

      For reference, in case it's of importance, I'm using sqlite3.

      5 votes
    13. Open Standards Are Simple

      (I am not directly posting as a link, as I have originally shared this over Gemini, which I don't think a majority of the people here have a client for, and directly linking to a proxy just seemed...

      (I am not directly posting as a link, as I have originally shared this over Gemini, which I don't think a majority of the people here have a client for, and directly linking to a proxy just seemed weird to me. So here are both the original and proxied links for people to choose between)

      gemini://ebc.li/posts/open-standards-are-simple.gmi (HTTP Proxy)

      13 votes
    14. What programming/technical projects have you been working on?

      This is a recurring post to discuss programming or other technical projects that we've been working on. Tell us about one of your recent projects, either at work or personal projects. What's...

      This is a recurring post to discuss programming or other technical projects that we've been working on. Tell us about one of your recent projects, either at work or personal projects. What's interesting about it? Are you having trouble with anything?

      5 votes
    15. Architecture for untrained software engineers (Python)

      Hey everyone, I've been programming for some time now but notice without any formalized education in CS I often get lost in the weeds when it comes to developing larger applications. I'm familiar...

      Hey everyone,

      I've been programming for some time now but notice without any formalized education in CS I often get lost in the weeds when it comes to developing larger applications. I'm familiar with the principles of TDD and SOLID - which have helped with maintainability - however still feel that I'm lacking in the ability to architect a properly structured system. As an example, I'm currently developing a flask REST API for a website (just for learning purposes). This involves parsing a html response and serializing the result as JSON. I'm still quite unclear as to structuring this sort of thing. If any more experienced developers could point me in the right direction/offer up their opinion I'd be very appreciative. Currently I have something like this (based - I hope correctly? - on uncle bob's clean architecture).

      Firstly, I'm defining the domain model. i.e the structure of the API response. Then, from outside in.

      1. Infrastructure (Flask): User makes request via interface (in my case a request to some endpoint)
      2. Adapters: request object checks if the request is valid (on the way back it checks if the response is valid) - Is this layer only for error handling?
      3. Repository: I'm struggling a bit here, AFAIUI this layer is traditionally a database. In my case however, where the request is valid, is this where I should handle the networking layer? i.e all the requests to return the website source? I'm also confused given at this stage I should be returning the relevant domain model, like an ORM, but as my data is unstructured, in order to do this I need to transform the response first. Where would it be best to handle this?
      4. Use Cases: Here I transform the domain model depending on the request. For example, filter all objects by id. Have I understood this correctly?
      5. Serializers: Encode the domain model as JSON to return from flask route.

      If you got this far, thanks so much for reading. I really hope to hear the opinions of more experienced devs who can steer me in the right direction/correct me should I have misunderstood anything.

      8 votes
    16. Looking for a simple language to build a compiler for

      I've recently built a brainfuck just-in-time compiler and I'm looking for my next project. I think compiling a more complicated (and more easily written) language would build on what I've learned...

      I've recently built a brainfuck just-in-time compiler and I'm looking for my next project. I think compiling a more complicated (and more easily written) language would build on what I've learned so far. Rather than design my own language from the ground up, I'd prefer to work with a toy language that already has existing programs and a spec. This would both save me some work and give me more solid ground to build upon.

      6 votes
    17. What programming/technical projects have you been working on?

      This is a recurring post to discuss programming or other technical projects that we've been working on. Tell us about one of your recent projects, either at work or personal projects. What's...

      This is a recurring post to discuss programming or other technical projects that we've been working on. Tell us about one of your recent projects, either at work or personal projects. What's interesting about it? Are you having trouble with anything?

      12 votes